Next.js Discord

Discord Forum

Revalidating a database call

Unanswered
Polar bear posted this in #help-forum
Open in Discord
Polar bearOP
I want to replace the fetch call with just fetching straight from the db. Can I still add a tag to it? Because I want to be able to revalidate it.
export default async function Home() {
let page = 0;
const res = await fetch(${process.env.NEXT_PUBLIC_URL}/api/posts, {
next: { tags: ['posts'] },
});
const posts = await res.json();

const session = await getServerSession(options);

return (
<main className="flex justify-center">
<section className="fixed w-[25vw] left-0">
{/* <Button>Create Post</Button> */}
</section>
<section className="flex flex-col gap-8 post-width">
{session ? (
<CreatePostForm session={session} />
) : (
<Card className="post-width">
<CardContent className="py-3 flex items-center gap-3">
<InformationCircleIcon className="w-6 h-6" />

<p>
<Link href="/signin" className="text-primary underline">
Sign in
</Link>{' '}
to create and interact with posts.
</p>
</CardContent>
</Card>

<Suspense fallback={<Spinner />}>
<PostList posts={posts} session={session} />
</Suspense>
</section>
<RightSection />
</main>
);
}

2 Replies