jackspace/claudeskillz/tanstack-query
- community
Checking that the SKILL.md file is still in the repository.
TanStack Query v5 (React Query) server-state management for React: QueryClient and QueryClientProvider setup, custom useQuery hooks, useMutation with error handling, useInfiniteQuery pagination, useSuspenseQuery, query keys, staleTime/gcTime caching, invalidation, prefetching, optimistic updates, and React Query Devtools. Use when adding data fetching to a React app, debugging stale data or caching problems, fixing request waterfalls or background refetching, or migrating React Query v4 to v5 breaking changes: cacheTime renamed to gcTime, isLoading renamed to isPending, required object syntax, initialPageParam required, keepPreviousData removed in favor of placeholderData, and onSuccess/onError query callbacks removed.
Install
npx vskill@latest install jackspace/claudeskillz/tanstack-querySKILL.md
TanStack Query (React Query) v5
Status: Production Ready ✅ Last Updated: 2025-10-22 Dependencies: React 18.0+, TypeScript 4.7+ (recommended) Latest Versions: @tanstack/react-query@5.90.5, @tanstack/react-query-devtools@5.90.2
Quick Start (5 Minutes)
1. Install Dependencies
Why this matters:
- TanStack Query v5 requires React 18+ (uses useSyncExternalStore)
- DevTools are essential for debugging queries and mutations
- v5 has breaking changes from v4 - use latest for all fixes
2. Set Up QueryClient Provider
CRITICAL:
- Wrap entire app with
QueryClientProvider - Configure
staleTimeto avoid excessive refetches (default is 0) - Use
gcTime(notcacheTime- renamed in v5) - DevTools should be inside provider
3. Create First Query
CRITICAL:
- v5 requires object syntax:
useQuery({ queryKey, queryFn }) - Use
isPending(notisLoading- that now means "pending AND fetching") - Always throw errors in queryFn for proper error handling
- QueryKey should be array for consistent cache keys
4. Create First Mutation
Why this works:
- Mutations use callbacks (
onSuccess,onError,onSettled) - queries don't invalidateQueriestriggers background refetch- Mutations don't cache by default (correct behavior)
The 7-Step Setup Process
Step 1: Install Dependencies
Package roles:
@tanstack/react-query- Core React hooks and QueryClient@tanstack/react-query-devtools- Visual debugger (dev only, tree-shakeable)@tanstack/eslint-plugin-query- Catches common mistakes
Version requirements:
- React 18.0 or higher (uses
useSyncExternalStore) - TypeScript 4.7+ for best type inference (optional but recommended)
Step 2: Configure QueryClient
Key configuration decisions:
staleTime vs gcTime:
staleTime: How long until data is considered "stale" and might refetch0(default): Data is immediately stale, refetches on mount/focus1000 * 60 * 5: Data fresh for 5 min, no refetch during this timeInfinity: Data never stale, manual invalidation onlygcTime: How long unused data stays in cache1000 * 60 * 5(default): 5 minutesInfinity: Never garbage collect (memory leak risk)
When to refetch:
refetchOnWindowFocus: true- Good for frequently changing data (stock prices)refetchOnWindowFocus: false- Good for stable data or during developmentrefetchOnMount: true- Ensures fresh data when component mountsrefetchOnReconnect: true- Refetch after network reconnect
Step 3: Wrap App with Provider
Provider placement:
- Must wrap all components that use TanStack Query hooks
- DevTools must be inside provider
- Only one QueryClient instance for entire app
DevTools configuration:
initialIsOpen={false}- Collapsed by defaultbuttonPosition="bottom-right"- Where to show toggle button- Automatically removed in production builds (tree-shaken)
Step 4: Create Custom Query Hooks
Pattern: Reusable Query Hooks
Why use queryOptions factory:
- Type inference works perfectly
- Reusable across
useQuery,useSuspenseQuery,prefetchQuery - Consistent queryKey and queryFn everywhere
- Easier to test and maintain
Query key structure:
['todos']- List of all todos['todos', id]- Single todo detail['todos', 'filters', { status: 'completed' }]- Filtered list- More specific keys are subsets (invalidating
['todos']invalidates all)
Step 5: Implement Mutations with Optimistic Updates
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 95 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/tanstack-query/SKILL.md
Popularity
- Repository stars
- 14
- Repository forks
- 6
- 7-day trend score
- 14
Stars and forks are for the whole GitHub repository, not this skill alone. Refreshed 11 May 2026, 5 months ago.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/jackspace/claudeskillz/tanstack-query)