State Management · Senior · Question 24 of 75
How do you pass server-prefetched TanStack Query data to client components in the Next.js App Router?
- ✓Correct answer:
prefetchQueryon the server,dehydrate, then<HydrationBoundary state> - 2Store it in
localStorageon the server - 3Use the
ssr: trueoption ofuseQuery
Explanation
A per-request QueryClient prefetches and serializes the cache; the client HydrationBoundary puts it into the browser cache, so useQuery with the same key renders immediately without a refetch.