Skip to main content
The HydrationBoundary component is used to hydrate dehydrated query data on the client. This is essential for server-side rendering (SSR) with TanStack Query.

Import

Signature

Props

DehydratedState | null | undefined
required
The dehydrated state object obtained from dehydrate(queryClient) on the server.
HydrateOptions
Optional hydration options.
React.ReactNode
The React components that will have access to the hydrated data.
QueryClient
Optional QueryClient instance. If not provided, uses the QueryClient from context.

Examples

Basic Usage with Next.js App Router

Client Component Using Hydrated Data

With Next.js Pages Router

With Custom Options

Multiple Hydration Boundaries

With Infinite Queries

Conditional Hydration

With Streaming (React Server Components)

Behavior

The HydrationBoundary component:
  1. Hydrates the dehydrated state into the QueryClient cache
  2. Intelligently handles queries that already exist in the cache
  3. For new queries, hydrates them immediately during render
  4. For existing queries, defers hydration until after render (to avoid updating during transitions)
  5. Compares timestamps to determine if hydrated data is newer than cached data
  6. Works seamlessly with React Suspense and Server Components

Notes

HydrationBoundary must be used within a QueryClientProvider component.
The state prop can be null or undefined, in which case no hydration occurs.
Hydration happens during render for new queries and after render for existing queries to support React transitions.
When using with Next.js App Router, the server component should create a new QueryClient and pass the dehydrated state to the client component.
The dehydrated state is serializable and can be passed through Next.js props or other serialization boundaries.