tanstack-query

Configures and uses TanStack Query v5 for React app server-state management.

16|7|Updated Nov 20, 2025
One-click install
npx skills add https://github.com/jackspace/ClaudeSkillz --skill tanstack-query-jackspace
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: tanstack-query
Source: https://github.com/jackspace/ClaudeSkillz/tree/main/skills/tanstack-query
Command: npx skills add https://github.com/jackspace/ClaudeSkillz --skill tanstack-query-jackspace

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires @tanstack/react-query, @tanstack/react-query-devtools, and includes references (resource) components.

What problem does it solve?

This Skill provides comprehensive guidance for TanStack Query v5 (React Query) in React apps, covering setup, useQuery, useMutation, caching strategies, v4-to-v5 migration, optimistic updates, and debugging patterns.

Core Features & Use Cases

  • QueryClient setup and global caching policies
  • useQuery, useMutation, useInfiniteQuery patterns
  • Optimistic updates and cache invalidation
  • v4 to v5 migration guidance
  • DevTools setup and testing patterns

Quick Start

Install dependencies, set up QueryClient, and create basic useQuery/useMutation examples.

Frequently Asked Questions about tanstack-query

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I set up TanStack Query for server state management in React?

TanStack Query manages server state through QueryClient setup and useQuery hooks. Install @tanstack/react-query, create a QueryClient instance, wrap your app with QueryClientProvider, then use useQuery with queryKey and queryFn objects to fetch and cache data automatically.

What's the difference between useQuery and useMutation in TanStack Query?

useQuery fetches and caches data automatically with background refetching and synchronization. useMutation handles side effects like POST, PUT, DELETE requests and triggers cache invalidation. Use useQuery for reads and useMutation for writes that modify server state.

How do I migrate from React Query v4 to TanStack Query v5?

TanStack Query v5 replaces staleTime with gcTime for garbage collection and uses object syntax for useQuery configuration. Update imports from react-query to @tanstack/react-query, replace staleTime references, and refactor useQuery calls to object format with queryKey and queryFn.

Can I use optimistic updates with TanStack Query mutations?

Yes, optimistic updates in TanStack Query update the cache immediately before the mutation completes, then rollback on failure. Use useMutation's onMutate callback to update QueryClient cache, then handle onSuccess or onError to finalize or revert changes.

How do I debug TanStack Query issues in my React app?

Install @tanstack/react-query-devtools to visualize queries, mutations, and cache state in real time. DevTools reveals query timing, refetch behavior, cache invalidation patterns, and error states, helping identify stale data and synchronization problems.

Does TanStack Query support infinite queries and pagination?

Yes, useInfiniteQuery handles pagination and infinite scroll by managing page cursors and concatenating results across fetches. Configure it with queryKey, queryFn, and getNextPageParam to load additional pages on demand without re-fetching previous data.