trpc-tanstack-integration

Use when adding tRPC and TanStack Query integration to a TypeScript project, especially Next.js App Router projects. Triggers: setup trpc, integrate tanstack query, create trpc router/context/provider, add api client server client hydration.

Safety Notice

This listing is imported from skills.sh public index metadata. Review upstream SKILL.md and repository scripts before running.

Copy this and send it to your AI assistant to learn

Install skill "trpc-tanstack-integration" with this command: npx skills add comradesharf/sembilan-skills/comradesharf-sembilan-skills-trpc-tanstack-integration

tRPC + TanStack Query Integration

Goal

Set up end-to-end type-safe API integration using:

  • @trpc/server
  • @trpc/client
  • @trpc/tanstack-react-query
  • @tanstack/react-query
  • optional transformer (devalue or superjson)

This skill should perform implementation, not just planning.

Bundled Reusable Templates

Use the prebuilt templates in this skill as the default implementation source.

  • templates/next-app-router/server/trpc.ts
  • templates/next-app-router/server/app-router.ts
  • templates/next-app-router/app/api/trpc/[trpc]/route.ts
  • templates/next-app-router/client/query-client.ts
  • templates/next-app-router/client/trpc-react.tsx
  • templates/next-app-router/server/trpc-rsc.tsx
  • templates/next-app-router/README.md

When integrating, copy these files into the target project and adapt import paths and auth session typing.

Workflow

  1. Detect project shape before editing.
  • Check framework (next, vite, react, node) from package.json.
  • Detect package manager from lockfiles (pnpm-lock.yaml, package-lock.json, yarn.lock, bun.lockb).
  • Detect routing/runtime style (Next.js App Router vs Pages Router vs SPA).
  1. Install required dependencies.
  • Runtime deps:
    • @trpc/server
    • @trpc/client
    • @trpc/tanstack-react-query
    • @tanstack/react-query
    • zod
    • devalue
  • Add framework-specific deps only if needed by detected architecture.
  1. Copy templates first.
  • For Next.js App Router, copy files from templates/next-app-router/.
  • Follow templates/next-app-router/README.md for destination mapping.
  • After copying, update imports and aliases to match the target project.
  1. Create server foundation.
  • Add trpc initializer with:
    • context typing
    • router, publicProcedure, optional protectedProcedure
    • consistent error formatting for Zod validation issues
    • transformer serialize/deserialize setup
  • Add root router (appRouter) and exported AppRouter type.
  1. Expose server endpoint.
  • For Next.js App Router: create app/api/trpc/[trpc]/route.ts using fetchRequestHandler.
  • Build context per request (auth/session if available).
  • Add structured logging for non-auth errors.
  1. Create TanStack Query client factory.
  • Add a reusable makeQueryClient() with sane defaults:
    • non-zero staleTime
    • hydration/dehydration serializer support
    • query/mutation error handling hooks
  • Export inferred API input/output types from AppRouter if helpful.
  1. Create client provider.
  • Implement a TRPCReactProvider as a client component.
  • Wrap app tree with:
    • QueryClientProvider
    • TRPCProvider from createTRPCContext<AppRouter>()
  • Use browser singleton query client to avoid recreation on suspense.
  1. Add server-side helper (when SSR/RSC exists).
  • Provide RSC helper utilities for:
    • prefetching query options
    • creating server-side caller
    • hydration boundary wrapper
  • Use request-aware context/session where auth exists.
  1. Wire providers into app layout.
  • Ensure root layout or app provider tree includes the TRPC/TanStack provider.
  • Preserve existing provider order and do not break existing context dependencies.
  1. Validate integration.
  • Run type-check/lint/build commands available in repo.
  • Confirm one read query and one mutation compile and run.
  • If tests exist for API layer, run relevant subset.

Implementation Rules

  • Prefer adapting existing project conventions (logger, auth, folder layout) over introducing new patterns.
  • Reuse existing serialization approach if project already uses one.
  • Avoid replacing unrelated files; keep edits minimal and additive.
  • If authentication exists, include protectedProcedure; otherwise keep public-only setup.
  • If project already has partial integration, complete missing pieces instead of duplicating files.

Next.js App Router Reference Layout

Use this structure when no established convention exists:

  • src/server/trpc.ts
  • src/server/routers/_app.ts
  • app/api/trpc/[trpc]/route.ts
  • src/lib/trpc-client.tsx
  • src/lib/query-client.ts
  • src/lib/trpc-rsc.tsx

Completion Checklist

  • Template files copied from this skill and adjusted for target project paths.
  • Dependencies installed.
  • AppRouter exported.
  • API route handler wired.
  • React Query and TRPC provider mounted in app tree.
  • Client can call at least one procedure with inferred types.
  • Type-check passes.
  • No duplicate provider/query-client instances introduced.

Source Transparency

This detail page is rendered from real SKILL.md content. Trust labels are metadata-based hints, not a safety guarantee.

Related Skills

Related by shared tags or category signals.

Coding

openclaw-version-monitor

监控 OpenClaw GitHub 版本更新,获取最新版本发布说明,翻译成中文, 并推送到 Telegram 和 Feishu。用于:(1) 定时检查版本更新 (2) 推送版本更新通知 (3) 生成中文版发布说明

Archived SourceRecently Updated
Coding

ask-claude

Delegate a task to Claude Code CLI and immediately report the result back in chat. Supports persistent sessions with full context memory. Safe execution: no data exfiltration, no external calls, file operations confined to workspace. Use when the user asks to run Claude, delegate a coding task, continue a previous Claude session, or any task benefiting from Claude Code's tools (file editing, code analysis, bash, etc.).

Archived SourceRecently Updated
Coding

ai-dating

This skill enables dating and matchmaking workflows. Use it when a user asks to make friends, find a partner, run matchmaking, or provide dating preferences/profile updates. The skill should execute `dating-cli` commands to complete profile setup, task creation/update, match checking, contact reveal, and review.

Archived SourceRecently Updated