Skip to content

tRPC v12 isn’t on npm yet. The @trpc12/* packages on this site can’t be installed until it’s released. Use v11 today

tRPC

React and Next.js

Which package to fetch with in React, and the pages for server components, Server Actions and route handlers.

On this page

React has three ways to fetch, and the server side of an RSC app has three more pieces. Pick one way to fetch; the server pieces work with any of them.

Fetching in components

PackageModelStability
@trpc12/tanstack-react-queryTanStack Query's options, cache and devtools, with useTrpc() and useSubscriptionstable
@trpc12/experimental-reactLoaders start queries and components read them with use(); cache features are linksexperimental
@trpc12/experimental-react-atomQueries, mutations and subscriptions as Effect atoms, typed with each procedure's errorsexperimental

Start with TanStack Query unless you already use Effect Atom, or want Suspense without a query cache.

On the server

  • React Server Components: createTrpcRsc from @trpc12/tanstack-react-query/rsc prefetches in server components, streams pending queries to the browser, and tags Next's data cache by query key.
  • Server Actions: experimental_createAction from @trpc12/trpc/actions turns procedures into actions that take typed input or FormData, for useActionState and 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.

Pages under React and Next.js