Skip to main content

trpc-patterns

Implement ChatJS tRPC routers, TanStack Query hooks, mutations, and cache invalidation. Use when adding or changing tRPC procedures or their React consumers in apps/chat.

Source facts

Repository
FranciscoMoretti/chat-js
Last source activity
September 12, 2026 at 06:41
Detected SKILL.md language
English
Stars
1,200
Forks
122

Install options

The review-first prompt is selected by default. You can switch to a direct command or download a local copy.

Review the source files

Read SKILL.md and any companion files shown by SkillsMP before deciding whether to install.

Showing SKILL.md

SKILL.md
Source instructions · Read-only preview
name
trpc-patterns
description
Implement ChatJS tRPC routers, TanStack Query hooks, mutations, and cache invalidation. Use when adding or changing tRPC procedures or their React consumers in apps/chat.
# ChatJS tRPC patterns ## Backend - Add feature routers under `apps/chat/trpc/routers/*.router.ts` and register them in `apps/chat/trpc/routers/_app.ts`. - Use `protectedProcedure` for authenticated operations. - Validate inputs with Zod and verify ownership before mutations. - Keep database access in `apps/chat/lib/db/queries.ts`. ## React queries Use `useTRPC()` with TanStack Query: ```tsx const trpc = useTRPC(); const query = useQuery({ ...trpc.feature.list.queryOptions(), enabled: Boolean(condition), }); ``` For mutations, use generated mutation options and invalidate related keys after success: ```tsx const trpc = useTRPC(); const queryClient = useQueryClient(); const mutation = useMutation( trpc.feature.update.mutationOptions({ onSuccess: () => queryClient.invalidateQueries({ queryKey: trpc.feature.list.queryKey(), }), }) ); ``` Handle loading and error states in the consumer.
View on GitHub