tanstack-query

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

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

SYSTEM DOCUMENTATION & REQUIREMENTS

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

What problem does it solve? Managing server state in frontend 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 snapshots and rollback logic to update the UI before server confirmation. - Pagination, Infinite Scroll & SSR: Implement useInfiniteQuery, placeholderData pagination, prefetching in route loaders, and hydration for server-rendered apps. - Use Case: Build a dashboard that fetches users and projects in parallel, prefetches detail pages on hover, and optimistically adds new todos with automatic rollback on failure. ## 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 with TanStack Query?▼

Use the useQuery hook with a unique queryKey array and a queryFn that returns a promise. TanStack Query automatically caches the result, deduplicates requests, and refetches stale data in the background based on your staleTime configuration.

How to do optimistic updates in React Query mutations?▼

In useMutation's onMutate callback, cancel outgoing queries with cancelQueries, snapshot the current cache with getQueryData, then update it with setQueryData. Return the snapshot as context and restore it in onError to roll back failed mutations.

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 stays in memory before garbage collection. Setting staleTime higher than gcTime can cause data to be collected while still marked fresh.

Does TanStack Query support infinite scrolling and pagination?▼

Yes, useInfiniteQuery handles cursor-based infinite scrolling with getNextPageParam and fetchNextPage. For traditional pagination, use useQuery with the page in the queryKey and placeholderData set to the previous data to avoid loading flickers.

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

Queries retry failed requests three times by default, which slows tests. Set retry to false and gcTime to Infinity in the test QueryClient, and always wrap tested components with a fresh QueryClientProvider to avoid shared cache state.