How to re-run a function in Server components on navigation to get fresh data?
Anyone know how to make sure async functions in the server components rerun when navigated to? They’re only being called on first mount currently. When you link back to a page.js server component the async data function doesn’t rerun. Using app directory in NextJS 13
4 Replies
I think you would just need to use a client component
https://beta.nextjs.org/docs/data-fetching/mutating There is instuctions
Data Fetching: Mutating | Next.js
Learn how to mutate data inside Next.js applications.
I believe that documentation is for client components not server. NextJS now makes layout and page files server components by default and recommends keeping it that way which is why I’m inquiring on this. Since a lot of calls will need to be done in these main files
Yeah I’m good to go with client components if needed which is why I’m asking for server. App directory also makes these components server by default so I’m working through their recommended workflow
Sorry, I think I readed question wrong. Was thinking you are mutating and want to fetch new data after.