App Directory: Trigger update in other component after mutation
Unanswered
Brown bear posted this in #help-forum
Brown bearOP
Hi all! Is there a way to trigger a refetch in another component after updating some data? E.g. in some deep route I delete an entry and I want to show the entry count in a sidebar that is placed in the root layout.
I tried
I tried
revalidateTag, but as far as I understand it only marks the cache as invalid, it doesn't refetch itself.12 Replies
@Brown bear Hi all! Is there a way to trigger a refetch in another component after updating some data? E.g. in some deep route I delete an entry and I want to show the entry count in a sidebar that is placed in the root layout.
I tried `revalidateTag`, but as far as I understand it only marks the cache as invalid, it doesn't refetch itself.
when a route is invalidated ALL the components will be prerendered
when components are prerendered it will be refetched again
Brown bearOP
Ah so I can just
revalidatePath('/')? But that means that everything will get refetched, right?yep
i have a somewhat related demo
but instead of fetch im using random number generator
so im not sure if it behaves the same for next's
fetch()Brown bearOP
Thanks for the example alfon! Do you maybe have a link to the example's source code?
Brown bearOP
I'm not sure if I understand how the refetching works.
If I understand the docs correctly,
If I understand the docs correctly,
revalidatePath doesn't actually load any data, it just invalidates it. How do I load the up-to-date data then? If I currently delete an entry, I have to reload the entire page in order for the sidebar to show the up-to-date entry count.@Brown bear I'm not sure if I understand how the refetching works.
If I understand the docs correctly, `revalidatePath` doesn't actually load any data, it just invalidates it. How do I load the up-to-date data then? If I currently delete an entry, I have to reload the entire page in order for the sidebar to show the up-to-date entry count.
by invalidating it it tells the nextjs server to render server components as opposed and update the dom to the latest version without refreshing the page from scratch