Revalidate Route
Unanswered
Sloth bear posted this in #help-forum
Sloth bearOP
I have some server actions for talking to the db. Do I need to revalidatePath every path that has changed data after a db mutation? This would mean to just revalidate the root with all it's sub paths or a whole lot of single path? Or is there any way to use revalidateTag with server actions?
11 Replies
You can use revalidateTag inside server actions
Sloth bearOP
But how do I tag the specific things I need to revalidate?
I know how to do it with fetch but no idea when calling a server action
revalidateTag('your-tag')
example from my repository:
export const getThoughts = unstable_cache(() => trpc.thoughts.all.query(), [], {
tags: ['thoughts'],
revalidate: 60,
})
export async function createThought(content: string) {
const { id: authorId } = await getCurrentUser()
const newThought = await trpc.thought.create.mutate({
content,
authorId,
})
revalidateTag('thoughts')
return newThought
}
Sloth bearOP
So I need to use unstablecache
Not really a fan of using a unstable function
if you are using fetch you don't
I'm using unstable cache because of trpc usage
just pass tag into fetch function
fetch('', {
next: {
tags: ['your-tag']
}
})