We can easily fetch data in our components, since they run on the server by default. This means we can just use the async / await
syntax to get data.
For example, here is our Todos page component:
import db from '@/utils/db';
const getTodos = async () => {
const todos = await db.todo.findMany();
return todos;
};
const TodosPage = async () => {
const todos = await getTodos();
return (
<main className="py-14 w-1/2 m-auto">
....
</main>
);
};
export default TodosPage;