* docs(*): add parameter and result property tables to reference function pages and an overview to overloaded ones * docs(*): link to the base type's properties when a parameter or result type has no property table * docs(framework/*/reference): regenerate reference docs * docs(framework/*/reference): regenerate reference docs * chore(scripts/generate-docs): restore the 'dirname' import that the merge dropped * docs(framework/*/reference): regenerate reference docs * docs(scripts/generate-docs): label overloads in the overview with their declared parameter and return types * docs(framework/*/reference): regenerate reference docs * docs(scripts/generate-docs): convert declared intersection types from the source so signatures keep their alias names * docs(framework/*/reference): regenerate reference docs * docs(scripts/generate-docs): reword a comment to avoid the unknown word 'inlines' * docs(scripts/generate-docs): skip a parameter table on overloaded pages when its heading is missing
2.9 KiB
| id | title |
|---|---|
| dehydrate | dehydrate |
function dehydrate(client: QueryClient, options?: DehydrateOptions): DehydratedState;
Defined in: packages/query-core/src/hydration.ts:245
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.
Parameters
client
The client whose cache is dehydrated.
options?
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.
options properties
| Property | Type | Description |
|---|---|---|
serializeData? |
TransformerFn |
Transforms a query's data before it is dehydrated. Useful for non-JSON-serializable data. |
shouldDehydrateMutation? |
(mutation: Mutation) => boolean |
Predicate to decide whether a given Mutation should be dehydrated. Defaults to defaultShouldDehydrateMutation. |
shouldDehydrateQuery? |
(query: Query) => boolean |
Predicate to decide whether a given Query should be dehydrated. Defaults to defaultShouldDehydrateQuery. |
shouldRedactErrors? |
(error: unknown) => boolean |
Predicate to decide whether a query's error should be redacted before dehydration. Errors are redacted (replaced with a generic Error('redacted')) unless this function is provided and returns false for the given error, in which case the original error is kept. |
Returns
The dehydrated state, with the included queries and mutations.
Result properties
Example
const queryClient = new QueryClient()
await queryClient.prefetchQuery({
queryKey: ['posts'],
queryFn: getPosts,
})
const dehydratedState = dehydrate(queryClient)