Open History to see the last commit
1---
2id: hydrate
3title: hydrate
4---
5β
6<!-- DO NOT EDIT: this page is autogenerated from the type comments -->
7β
8```ts
9function hydrate(
10 client: QueryClient,
11 dehydratedState: Partial<DehydratedState>,
12 options?: HydrateOptions
13): void;
14```
15β
16Defined in: [packages/query-core/src/hydration.ts:306](https://github.com/TanStack/query/blob/main/packages/query-core/src/hydration.ts#L306)
17β
18Restores a `DehydratedState` (as produced by `dehydrate`) into a `QueryClient`'s cache, typically to seed the
19client with data already fetched on the server. `mutations` and `queries` are each optional on `dehydratedState`.
20Queries not yet in the cache are built from the dehydrated snapshot; queries that already exist are only updated
21when the dehydrated data is newer than what's already cached. Newly built queries have their `fetchStatus` reset
22to `'idle'` so they don't hydrate stuck in a fetching state. If a dehydrated query still had an in-flight
23promise, it is resumed via `query.fetch()` (reusing that promise as `initialPromise`) rather than re-invoking
24`queryFn`.
25β
26## Parameters
27β
28### client
29β
30`QueryClient`
31β
32The client whose cache is restored into.
33β
34### dehydratedState
35β
36`Partial`\<[`DehydratedState`](../interfaces/DehydratedState.md)\>
37β
38The dehydrated state, e.g. produced by `dehydrate` on the server.
39β
40<a id="dehydratedState-properties"></a>
41β
42#### `dehydratedState` properties
43β
44Built from [`DehydratedState`](../interfaces/DehydratedState.md#properties). See the type above for what it changes.
45β
46### options?
47β
48[`HydrateOptions`](../interfaces/HydrateOptions.md)
49β
50`defaultOptions` merged into every restored query and mutation (on top of the
51client's `defaultOptions.hydrate`), and `deserializeData` to reverse `serializeData`.
52β
53<a id="options-properties"></a>
54β
55#### `options` properties
56β
57| Property | Type | Description |
58| ------ | ------ | ------ |
59| <a id="options-property-defaultoptions"></a> `defaultOptions?` | `object` | Options applied to the queries and mutations restored from the dehydrated state. |
60| `defaultOptions.deserializeData?` | `TransformerFn` | Transforms a query's `data` after it is read from the dehydrated state, reversing `serializeData`. |
61| `defaultOptions.mutations?` | `MutationOptions`\<`unknown`, `Error`, `unknown`, `unknown`\> | Default options merged into every mutation restored from the dehydrated state. |
62| `defaultOptions.queries?` | `QueryOptions`\<`unknown`, `Error`, `unknown`, readonly `unknown`[], `never`\> | Default options merged into every query restored from the dehydrated state. |
63β
64## Returns
65β
66`void`
67β
68## Example
69β
70```ts
71// dehydratedState was produced by `dehydrate` on the server
72// and sent to the client, e.g. embedded in server-rendered markup.
73const queryClient = new QueryClient()
74β
75hydrate(queryClient, dehydratedState)
76```