achieving ppr on nextjs with react query #9196
-
Hi, I'd like to propose a pattern inspired by the latest version of swr to easily integrate react query with nextjs ppr feature "use client";
...
const result = useQuery({
queryKey: ["user"],
queryFn: browserSideDataFetching,
initialData: use(unwrappedPromise),
});
... here here is a working example https://codesandbox.io/p/devbox/nextjs-15-forked-88dkt3?workspaceId=ws_DPC2Xnz6thfcUc5K7SwW5M |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
why not do this with hydration and sending non-awaited promised down like shown in the docs? the problem with |
Beta Was this translation helpful? Give feedback.
why not do this with hydration and sending non-awaited promised down like shown in the docs?
https://tanstack.com/query/v5/docs/framework/react/guides/advanced-ssr#streaming-with-server-components
the problem with
initialData
is that it will be ignored if there is data in the cache already, but the fetch on the server will start every time you navigate to the page. hydration solves this because it can overwrite existing data in the cache.