Open History to see the last commit
1---
2id: useHydrate
3title: useHydrate
4---
5β
6<!-- DO NOT EDIT: this page is autogenerated from the type comments -->
7β
8```ts
9function useHydrate(
10 state?: unknown,
11 options?: HydrateOptions,
12 queryClient?: QueryClient
13): void;
14```
15β
16Defined in: [packages/svelte-query/src/useHydrate.ts:31](https://github.com/TanStack/query/blob/main/packages/svelte-query/src/useHydrate.ts#L31)
17β
18Adds a previously dehydrated `state` into the `queryClient` (from the nearest context, or the one
19passed explicitly). If the client already contains data, the new queries will be intelligently merged based
20on update timestamp. `HydrationBoundary` wraps this β use it directly only if you need to hydrate from your
21own component instead.
22β
23## Parameters
24β
25### state?
26β
27`unknown`
28β
29The dehydrated state to hydrate into the cache, as produced by `dehydrate`.
30β
31### options?
32β
33[`HydrateOptions`](../interfaces/HydrateOptions.md)
34β
35[HydrateOptions](../interfaces/HydrateOptions.md) to control the hydration.
36β
37<a id="options-properties"></a>
38β
39#### `options` properties
40β
41| Property | Type | Description |
42| ------ | ------ | ------ |
43| <a id="options-property-defaultoptions"></a> `defaultOptions?` | `object` | Options applied to the queries and mutations restored from the dehydrated state. |
44| `defaultOptions.deserializeData?` | `TransformerFn` | Transforms a query's `data` after it is read from the dehydrated state, reversing `serializeData`. |
45| `defaultOptions.mutations?` | [`MutationOptions`](../interfaces/MutationOptions.md)\<`unknown`, `Error`, `unknown`, `unknown`\> | Default options merged into every mutation restored from the dehydrated state. |
46| `defaultOptions.queries?` | [`QueryOptions`](../interfaces/QueryOptions.md)\<`unknown`, `Error`, `unknown`, readonly `unknown`[], `never`\> | Default options merged into every query restored from the dehydrated state. |
47β
48### queryClient?
49β
50[`QueryClient`](../classes/QueryClient.md)
51β
52Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will
53be used.
54β
55## Returns
56β
57`void`
58β
59## Example
60β
61Server-side prefetch handed off to the client via `dehydrate` β `dehydratedState` would typically come
62from a server load function that prefetched with `queryClient.query` and called `dehydrate(queryClient)`:
63```svelte
64<script lang="ts">
65 import { HydrationBoundary } from '@tanstack/svelte-query'
66 import type { DehydratedState } from '@tanstack/svelte-query'
67 import Posts from './Posts.svelte'
68β
69 let { dehydratedState }: { dehydratedState: DehydratedState } = $props()
70</script>
71β
72<HydrationBoundary state={dehydratedState}>
73 <Posts />
74</HydrationBoundary>
75```