export default async function Home() {
// fetching data directly into the database
const posts = await prisma.post.findMany();
// fetching data from a nextJs api endpoint that will fetch my database
const { posts } = await fetch('/api/posts')
return (
<main>
<AddPost />
{posts.map((post, key) => (
<Post {...post} key={`post_${key}`} />
))}
</main>
);
}
I really prefer to fetch the database directly, but won't that disable the next fetch cache behavior?
The database query was the correct way to handle this on the /pages getServerSideProps, it feels wrong to run a request from NextJs to NextJs at component build time