Expert patterns for TanStack Query v5 (React Query). Caching, mutations, query key factories, and performance optimization.
Installation
Mit Codex oder Claude installieren Kopieren Sie diesen Prompt, fügen Sie ihn in Codex, Claude oder einen anderen Assistant ein und lassen Sie die Skill-Seite prüfen und installieren.
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.