← Back to DAGDA | Support | Source: https://github.com/trpc/examples-next-minimal-starter
Skip to content

Repository files navigation

Next.js App Router + tRPC

A minimal tRPC setup on the Next.js App Router with @trpc/tanstack-react-query, following the App Router setup guide.

  • src/trpc/routers/_app.ts: the router, with a greeting query and a loopData subscription
  • src/app/api/trpc/[trpc]/route.ts: the route handler serving it with the fetch adapter
  • src/trpc/server.tsx: trpc, prefetch and HydrateClient for server components
  • src/trpc/client.tsx: the TRPCReactProvider and useTRPC hook for client components
  • src/app/page.tsx: a server component that prefetches greeting and hands it to the client still pending
  • src/app/greeting.tsx: reads it with useSuspenseQuery, which suspends until it streams in
  • src/app/loop-data.tsx: useSubscription over server-sent events

Setup

npx create-next-app --example https://github.com/trpc/examples-next-minimal-starter trpc-minimal-starter
cd trpc-minimal-starter
npm i
npm run dev

Development

Start project

npm run dev        # starts next.js

Releases

Packages

Used by

Contributors

Languages