Skip to content
Source
Sign inSign up
TanStack/query
Open History to see the last commit

dehydrateQuery.md

45 lines1.2 KB

1---
2id: dehydrateQuery
3title: dehydrateQuery
4---
5​
6```ts
7function dehydrateQuery(
8 query: Query,
9 serializeData?: TransformerFn,
10 shouldRedactErrors?: (error: unknown) => boolean): DehydratedQuery;
11```
12​
13Defined in: [packages/query-core/src/hydration.ts:178](https://github.com/TanStack/query/blob/main/packages/query-core/src/hydration.ts#L178)
14​
15Dehydrates a single `Query` into a serializable `DehydratedQuery` snapshot. Note that most query config (e.g.
16`queryFn`, `staleTime`) is not dehydrated but instead meant to be configured again when consuming the
17de/rehydrated data, typically with `useQuery` on the client. If the query is still `pending`, its in-flight
18promise is dehydrated too so it can be resumed on the other side instead of re-fetched.
19​
20## Parameters
21​
22### query
23​
24[`Query`](../classes/Query.md)
25​
26The query to dehydrate.
27​
28### serializeData?
29​
30`TransformerFn`
31​
32Optional transform applied to `query.state.data` before it is included in the snapshot.
33​
34### shouldRedactErrors?
35​
36(`error`: `unknown`) => `boolean`
37​
38Optional predicate; if it returns `false` for the promise's rejection error, that
39error is kept as-is instead of being redacted.
40​
41## Returns
42​
43`DehydratedQuery`
44​
45The dehydrated query.