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 agreetingquery and aloopDatasubscriptionsrc/app/api/trpc/[trpc]/route.ts: the route handler serving it with the fetch adaptersrc/trpc/server.tsx:trpc,prefetchandHydrateClientfor server componentssrc/trpc/client.tsx: theTRPCReactProvideranduseTRPChook for client componentssrc/app/page.tsx: a server component that prefetchesgreetingand hands it to the client still pendingsrc/app/greeting.tsx: reads it withuseSuspenseQuery, which suspends until it streams insrc/app/loop-data.tsx:useSubscriptionover server-sent events
npx create-next-app --example https://github.com/trpc/examples-next-minimal-starter trpc-minimal-starter
cd trpc-minimal-starter
npm i
npm run devnpm run dev # starts next.js