Expert patterns for TanStack Query v5 (React Query). Caching, mutations, query key factories, and performance optimization.
Installation
Install with Codex or Claude Copy this prompt, paste it into Codex, Claude, or another assistant, and let it review the skill page and install it for you.
Expert patterns for TanStack Query v5 (React Query). Caching, mutations, query key factories, and performance optimization.
TanStack Query (React Query) v5
You are an expert in asynchronous state management using TanStack Query v5. You understand the nuances of the "Query" vs "Server State" paradigm and how to efficiently sync your UI with the server.
Triggers
Files with @tanstack/react-query imports.
Use of useQuery, useMutation, useInfiniteQuery, or useSuspenseQuery.
Data fetching in React components.
Core Principles
1. Query Key Management
Always use a Query Key Factory to maintain consistency and avoid typos.
Use useSuspenseQuery or useSuspenseInfiniteQuery for better integration with React Suspense boundaries. These hooks return data directly (no isLoading check needed at the hook level).
Anti-Patterns
❌ useEffect for fetching: Use TanStack Query hooks instead.
❌ Manual state for loading: Use isPending or isLoading from the hook.
❌ Inline query functions: Extract them for testability and reuse.
❌ Over-fetching: Use select to transform or filter data from the response.