function dehydrate(client: QueryClient, options: DehydrateOptions): DehydratedState;Defined in: packages/query-core/src/hydration.ts:239
Dehydrates a QueryClient's cache (queries and mutations) into a plain, serializable DehydratedState, typically to embed in server-rendered markup and later restore into a client-side QueryClient via hydrate. Which queries/mutations are included, and how their data/errors are transformed, is controlled by options, falling back to the client's dehydrate default options, and finally to defaultShouldDehydrateQuery / defaultShouldDehydrateMutation.
QueryClient
The client whose cache is dehydrated.
DehydrateOptions = {}
Controls which queries and mutations are included and how their data and errors are transformed. Each option falls back to the client's defaultOptions.dehydrate.
The dehydrated state, with the included queries and mutations.
const queryClient = new QueryClient()
await queryClient.prefetchQuery({
queryKey: ['posts'],
queryFn: getPosts,
})
const dehydratedState = dehydrate(queryClient)