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

dehydrateQuery.md

48 lines1.3 KB

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