Next.js · Middle · Question 34 of 75
How do you prefetch data for client components using TanStack Query in the App Router?
- ✓Correct answer:
prefetchQueryon the server andHydrationBoundary - 2Call
useQuerydirectly in an async server component - 3Put the
QueryClientinstance into the page'smetadataexport
Explanation
A server component creates a QueryClient, runs prefetchQuery and passes the cache state via <HydrationBoundary state={dehydrate(qc)}>. A client useQuery with the same key gets the data immediately. Hooks don't work in server components.