examples/react/suspense-streaming-nextjs-app-router
| Name | Last commit message | Last commit date |
|---|---|---|
| .. | ||
README.md
TanStack React Query Suspense Streaming Example (Next.js App Router)#
Streams suspense queries from the server with ReactQueryStreamedHydration, so each query's data reaches the client as it resolves.
Built with Next.js (App Router).
How it works#
src/services/wait/queries.tsdefineswaitQueries.detail(wait)withqueryOptions.src/services/wait/api.tscalls/api/wait, using an absolute URL whenenvironmentManager.isServer()istrue.src/app/providers.tsxcreates aQueryClientper request on the server and one in the browser, and wraps the app inReactQueryStreamedHydrationfrom@tanstack/react-query-next-experimental.src/app/page.tsxis a Client Component that rendersMyComponentwithuseSuspenseQuery(waitQueries.detail(wait))for waits from 100 to 1000 ms. Each of the first seven has its ownSuspenseboundary and appears as soon as its query resolves; the last three share one boundary and appear together.src/app/api/wait/route.tsis a route handler that responds withwaited ${wait}msafter the requested delay.
To run this example:
npm installnpm run dev