client-data-fetching
Installation
SKILL.md
Instructions
When to Use
- Use for TanStack Query v5 + RSC hydration without double fetch.
- Prefer
next-server-patternswhen the question is server-only data. - Prefer
server-caching-handbookfor tag/TTL stampedes.
Use TanStack Query v5 (@tanstack/react-query) with Next.js App Router without fighting RSC.
- Provider: wrap client subtree that needs queries - usually a
providers.tsxclient component imported fromlayout.tsx; do not wrap entire app in client unless necessary. - Keys: stable serializable arrays; include locale and filters; never embed secrets in keys.
- Server prefetch: when RSC fetches initial data, pass dehydrated state to client
HydrationBoundary+prefetchQuery- clientuseQuerymust use same key and compatiblequeryFnor rely on hydrated data. - Defaults: set sensible
staleTime(e.g. 30s–5m for dashboards); avoidrefetchOnWindowFocusstorm on sensitive forms - tune per query. - Mutations:
onSuccessinvalidate minimal key prefixes; optimistic updates only with rollback plan. - Errors: surface with boundaries (
error-loading-not-foundskill); do not leak server error bodies to toast without sanitization.
Outcomes
- Provider file outline + one
useQuery+ one RSC prefetch example names only (no full app).