Loading...
Loading...
TanStack Query v5 server state management for React. Covers query/mutation patterns, v4-to-v5 migration (object syntax, gcTime, isPending, keepPreviousData), optimistic updates via useMutationState, SSR/hydration with HydrationBoundary, infinite queries, offline/PWA support, error boundaries with throwOnError, and React 19 Suspense integration. Use when building data fetching, fixing migration errors, debugging hydration mismatches, implementing caching strategies, or configuring mutations.
npx skill4agent add oakoss/agent-skills tanstack-queryqueryFn| Pattern | API | Key Points |
|---|---|---|
| Basic query | | Include params in queryKey |
| Suspense query | | No |
| Parallel queries | | Dynamic parallel fetching |
| Dependent query | | Wait for prerequisite data |
| Query options | | Reusable, type-safe config |
| Basic mutation | | Invalidate on success |
| Mutation state | | Cross-component mutation tracking |
| Optimistic update | | Rollback in |
| Infinite query | | |
| Prefetch | | Preload on hover/intent |
| Invalidation | | Fuzzy-matches by default, active only |
| Cancellation | | Auto-cancel on key change |
| Select transform | | Structural sharing preserved |
| Skip token | | Type-safe conditional disabling |
| Serial mutations | | Same scope ID runs mutations in serial |
| v4 (Removed) | v5 (Use Instead) |
|---|---|
| |
| |
| |
| |
| |
| |
No | |
Error type | Error type defaults to |
| Mistake | Correct Pattern |
|---|---|
Checking | Data-first: check |
| Copying server state to local useState | Use data directly or derived state pattern |
| Creating QueryClient in component | Create once outside component or in useState |
Using | Include params in queryKey, let it refetch automatically |
| Same key for useQuery and useInfiniteQuery | Use distinct key segments (different cache structures) |
| Inline select without memoization | Extract to stable function or useCallback |
Using | Throw errors in queryFn (fetch doesn't reject on 4xx/5xx) |
| Manual generics on useQuery | Type the queryFn return, let inference work |
| Destructuring query for type narrowing | Keep query object intact for proper narrowing |
Using | Use conditional rendering to mount/unmount component |
| Not awaiting prefetch for SSR | Await |
| Use |
ExploreTaskcode-reviewer