tanstack-query
TanStack Query Best Practices
Patterns and conventions for TanStack Query v5 data fetching, caching, and mutations in React/TypeScript projects.
Core Mental Model
- Server state vs client state — TanStack Query manages server state (data from APIs). Do not duplicate it into
useStateor Redux; use those only for client state (UI state, form drafts). - Stale-while-revalidate — Cached data is served immediately, then validated in the background. Users see data fast; freshness happens transparently.
- Query keys = dependency arrays — Every variable that affects fetching belongs in the key. When the key changes, TanStack Query refetches automatically.
- Declarative over imperative — Drive refetching by changing key values (state, filters, IDs), not by calling
refetch()with new parameters. - Cache is the single source of truth — The query cache is the authoritative store for all server state. Read from it; never copy it elsewhere.
Quick Setup
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
More from kbravh/skills
svg-logo-creator
Create professional SVG logos from concept briefs or descriptions. Use when generating SVG logo files, creating logo variations (horizontal, vertical, icon-only), or implementing logo designs. Triggers on "create SVG logo," "generate logo," "make a logo," "logo SVG," "design a logo," or when given a logo concept brief from logo-ideation.
72logo-ideation
Brand discovery and logo concept development. Use when brainstorming logo ideas, exploring visual directions, analyzing competitor logos, or developing logo concepts before creation. Triggers on "logo ideas," "logo concept," "brand identity," "logo brainstorm," "competitor logos," "visual identity exploration," or any pre-design logo planning.
25prisma-expand-contract
Safe database schema migrations using the expand-and-contract pattern with Prisma ORM. Use when renaming columns/tables, changing column types, adding non-nullable columns, or any schema change requiring zero-downtime deployment.
9