Next.js Discord

Discord Forum

Re-fetching data in a server component

Unanswered
Argentine ant posted this in #help-forum
Open in Discord
Argentine antOP
Hey, currently using Server components and have a usecase to have some UI that's "live" - with this, how can I revalidate the data for these specific server components instead of revalidating all server components? Or, should I just keep it simple and use a client component and manage data fetching in that

14 Replies

Argentine antOP
wouldn't this approach cause all of the other server components to re-fetch too?
by fetch, I mean using server actions
@Ray I think you could try to set a tag to the fetch request in the server component and use `revalidateTag` with server action to revalidate it
Argentine antOP
thanks! So as an example of what i'd want to happen:

1) Server component provides some data to a child component, (graph) - this graph updates every 1 second, and the server function is directly hooked into the database to fetch the data

So i'm just trying to figure out what would be the best way to handle this server action execution from within the client component without every other server component from re-running
It might not be possible, which would just mean I'd have to fetch it from the client component but if I can help not having to create a route etc and doing it that way that'd be great
@Ray oh if its updating every 1 second then its better to use client component for that
Argentine antOP
Yeah I thought so, since it doesn't seem possible to really trigger a server component reload just for that one server component
would be cool to see though!
yeah you could use react-query/swr with server action to fetch the data on a interval
Argentine antOP
so maybe the server component can provide the initial data, then just call the server action in the client component
Argentine antOP
thanks for the help Ray
@Argentine ant thanks for the help Ray
you're welcome