tanstack-query

Implement server-state caching, fetching, and synchronization with TanStack Query v5.

Updated Sep 17, 2026
One-click install
npx skills add https://github.com/juanjaragavi/utilities-manager --skill tanstack-query-juanjaragavi
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: tanstack-query
Source: https://github.com/juanjaragavi/utilities-manager/tree/main/.agents/skills/tanstack-query
Command: npx skills add https://github.com/juanjaragavi/utilities-manager --skill tanstack-query-juanjaragavi

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires @tanstack/react-query, @tanstack/react-query-devtools.

What problem does it solve? Managing server state in React applications requires handling caching, background refetching, pagination, and optimistic updates manually, which leads to duplicated boilerplate and stale data bugs. ## Core Features & Use Cases - Declarative Data Fetching: Use useQuery with hierarchical query keys for automatic caching, deduplication, and background refetching. - Mutations & Optimistic Updates: Apply useMutation with onMutate rollback context to update the UI instantly and recover on errors. - Advanced Patterns: Infinite queries, dependent queries, Suspense integration, SSR hydration, and prefetching in route loaders. - Use Case: Build a paginated todo dashboard where list data stays cached across navigation, mutations update the UI optimistically, and related queries invalidate automatically after each change. ## Quick Start Set up TanStack Query in my React app with a QueryClientProvider and write a useQuery hook that fetches and caches a list of todos.

Frequently Asked Questions about tanstack-query

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

FAQPage Schema
How do I fetch and cache API data in React with TanStack Query?▼

Wrap your app in QueryClientProvider with a QueryClient, then call useQuery with a serializable queryKey array and a queryFn that returns a promise. TanStack Query caches the result, deduplicates requests, and refetches stale data automatically.

How do I do optimistic updates with useMutation?▼

In onMutate, cancel outgoing queries with cancelQueries, snapshot the current cache via getQueryData, then write the new value with setQueryData. Return the snapshot as context and restore it in onError to roll back on failure.

Does TanStack Query support infinite scrolling and pagination?▼

Yes. useInfiniteQuery handles cursor-based infinite lists with getNextPageParam and fetchNextPage, while regular useQuery with placeholderData set to the previous data keeps paginated views stable between page changes.

What is the difference between staleTime and gcTime in TanStack Query?▼

staleTime controls how long data is considered fresh before refetching, while gcTime controls how long unused cached data is kept before garbage collection. Setting staleTime higher than gcTime can cause data to be collected while still marked fresh.

Why is my TanStack Query test timing out or retrying?▼

The default retry setting causes repeated fetch attempts in tests. Configure the test QueryClient with retry: false and gcTime: Infinity, and always wrap tested hooks in a fresh QueryClientProvider to avoid shared cache state.