You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was looking at the new ReactQueryStreamedHydration examples, but it looks like the idea is to always fetch data from a client side component, never from a server one.
How can I have a server side component fetch some data, render it on the client, and send the cache to the client so that client side queries can make use of it?
// components/client-side-component.tsx"use client"exportconstClientSideComponent=()=>{// this should not trigger a network request as the same resource was// already loaded by the serverconst{ data }=useSuspenseQuery({queryKey: ['test'],queryFn()=>(awaitfetch('https://example.org/api/test')).json(),});return<p>{data.body}</p>;}
This should allow to share the cache between the client and the server.
I just don't understand why all of this has not been explored or documented anywhere?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I was looking at the new
ReactQueryStreamedHydration
examples, but it looks like the idea is to always fetch data from a client side component, never from a server one.How can I have a server side component fetch some data, render it on the client, and send the cache to the client so that client side queries can make use of it?
One approach I can think of is the following:
This should allow to share the cache between the client and the server.
I just don't understand why all of this has not been explored or documented anywhere?
Beta Was this translation helpful? Give feedback.
All reactions