TanStack
API Reference

HydrationBoundary

ts
function HydrationBoundary(__namedParameters): Element;

Defined in: preact-query/src/HydrationBoundary.tsx:87

HydrationBoundary adds a previously dehydrated state into the queryClient that would be returned by useQueryClient(). If the client already contains data, the new queries will be intelligently merged based on update timestamp.

Note: Only queries can be dehydrated with an HydrationBoundary.

Parameters

__namedParameters

HydrationBoundaryProps

Returns

Element

The provided children, rendered unconditionally. New queries in state are hydrated into the cache during render; for queries already in the cache, only newer dehydrated data is hydrated, in an effect after commit.

Examples

tsx
import { HydrationBoundary } from '@tanstack/preact-query'

function App() {
  return <HydrationBoundary state={dehydratedState}>...</HydrationBoundary>
}

Server-side prefetch handed off to the client via dehydrate:

tsx
import { HydrationBoundary, dehydrate, noop } from '@tanstack/preact-query'

async function ServerComponent() {
  const queryClient = getQueryClient()

  await queryClient
    .query({
      queryKey: ['posts'],
      queryFn: fetchPosts,
    })
    .catch(noop)

  return (
    <HydrationBoundary state={dehydrate(queryClient)}>
      <Posts />
    </HydrationBoundary>
  )
}