The QueriesHydration component is an async React Server Component (RSC) that prefetches an array of queries on the server and hydrates them into client components. This replaces the manual prefetchQuery + dehydrate + Hydrate boilerplate.
To enable independent HTML streaming, wrap each section of your UI in its own Suspense boundary and QueriesHydration component. This allows each section to stream to the client as its specific queries resolve.
Key details:
queries accepts an array of queryOptions or infiniteQueryOptions results.- Every entry must have a
queryKey. - All queries in the array are fetched in parallel using
Promise.all. - Render
QueriesHydration only in Server Components.
// app/posts/page.tsx — Server Component (no 'use client')
import { Suspense } from '@suspensive/react'
import { QueriesHydration } from '@suspensive/react-query-4'
import { postsQueryOptions, userQueryOptions } from './queries'
import { PostList, UserProfile } from './_components'
export default function PostsPage({ userId }: { userId: number }) {
return (
<>
<Suspense fallback={<div>Loading user...</div>}>
<QueriesHydration queries={[userQueryOptions(userId)]}>
<UserProfile userId={userId} />
</QueriesHydration>
</Suspense>
<Suspense fallback={<div>Loading posts...</div>}>
<QueriesHydration queries={[postsQueryOptions(userId)]}>
<PostList userId={userId} />
</QueriesHydration>
</Suspense>
</>
)
}