What problem does it solve?
This Skill provides a concise, opinionated set of best-practice rules and actionable examples to prevent common bugs and performance issues when using TanStack Query (React Query) in React applications. It reduces cache inconsistencies, excessive network requests, incorrect mutation handling, and SSR hydration problems by standardizing query keys, caching policies, mutation flows, and offline persistence strategies.
Core Features & Use Cases
- Query Key Discipline: guidance on array-structured, hierarchical, serializable keys and query key factories to avoid cache collisions and enable precise invalidation.
- Caching & Performance: recommendations for staleTime, gcTime, placeholderData vs initialData, structural sharing, and select-based transforms to minimize refetches and re-renders.
- Mutations & Optimistic Updates: patterns for onMutate snapshots, rollback context, targeted invalidation, and useMutationState for cross-component tracking.
- SSR, Prefetching & Offline: dehydrate/hydrate patterns, intent-based prefetching, networkMode options, and query persistence strategies for offline-first apps.
- Use Case: Audit or implement a data-fetching layer in a React/TanStack Query codebase to improve UX, reduce unnecessary requests, and eliminate stale or inconsistent UI states.
Quick Start
Review my React project's data fetching code and return prioritized, actionable fixes and code examples to align with TanStack Query best practices.