React and Next.js
Fetching in React, and the pages for server components, Server Actions and route handlers.
On this page
React fetches with @trpc12/tanstack-react-query: TanStack Query's options, cache and devtools, with useTrpc() and useSubscription. The server side of an RSC app has three more pieces.
On the server
- React Server Components:
createTrpcRscfrom@trpc12/tanstack-react-query/rscprefetches in server components, streams pending queries to the browser, and tags Next's data cache by query key. - Server Actions:
experimental_createActionfrom@trpc12/trpc/actionsturns procedures into actions that take typed input orFormData, foruseActionStateand optimistic updates. - Route handlers serve the router with
handler.fetch, as in any fetch runtime (Fetch runtimes).
None of these is Next-specific: they work with any React Server Components setup.