Next.js Discord

Discord Forum

cache revalidation with child component updating data

Unanswered
Purple Martin posted this in #help-forum
Open in Discord
Avatar
Purple MartinOP
I'm struggling to understand the logic behing cache revalidation when using server components.

I'm working on a simple app that displays a list of pictures. These are fetched by a server component.

In the same page, I'm using a client component that using react-hook-form to create a picture.

Is it possible to combine these two so that the data on the server components are re-fetched after my picture has been created ? Or do I have to convert my server component to a client component ?

3 Replies

Avatar
not-milo.tsx
You can refresh the page after submitting the form. Then if you're fetching your data with fetch you can secify how it should be cached and when it has to be revalidated. See this docs page: https://nextjs.org/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating#caching-data
Avatar
Purple MartinOP
Maybe I misudnerstood, but it seems like the documentation relies on API respnse coming from the next app. I'm using an external nest.js app
Avatar
not-milo.tsx
It doesn't matter where is the data coming from. If you're requesting it from a Next.js app then that's how you would control the caching behaviour.