tanstack-query

Manage React server-state with TanStack Query queries, mutations, and caching.

32|2|Updated Nov 5, 2025
One-click install
npx skills add https://github.com/tenequm/claude-plugins --skill tanstack-query-tenequm
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: tanstack-query
Source: https://github.com/tenequm/claude-plugins/tree/main/tanstack-query/skill
Command: npx skills add https://github.com/tenequm/claude-plugins --skill tanstack-query-tenequm

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill documents how to use TanStack Query v5 for fetching, caching, mutations, and server state management in React apps.

Core Features & Use Cases

  • Query keys and caching patterns
  • Data fetching, mutation handling, and cache invalidation
  • Infinite queries, prefetching, and performance best practices
  • Type-safe patterns with TypeScript

Quick Start

Install: npm install @tanstack/react-query Wrap app with QueryClientProvider and use useQuery / useMutation as shown in examples.

Frequently Asked Questions about tanstack-query

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

FAQPage Schema
How do I handle data fetching and caching in React without manual state management?

TanStack Query automates data fetching, caching, and server-state synchronization in React. Use useQuery with a queryFn that returns a promise and an array-based queryKey; the library handles cache lifecycle, background refetching, and stale data invalidation automatically.

Can I use TanStack Query with both REST and GraphQL APIs?

TanStack Query works with any data source that returns a promise, including REST and GraphQL. Define your queryFn to call either endpoint type, configure staleTime and gcTime for cache behavior, and use the same query and mutation hooks across both.

How do I implement optimistic updates and handle mutations in React?

Use useMutation with onSuccess and onSettled side effects to manage mutation outcomes and trigger cache invalidation. Optimistic updates let you update UI immediately while the server request completes, then reconcile if needed.

What's the best way to handle infinite scrolling or pagination with server-state data?

TanStack Query provides useInfiniteQuery for paginated or infinite-scroll data. It manages multiple pages in cache, tracks page state, and coordinates refetching—eliminating manual pagination logic and duplicate fetches.

Do I need TypeScript to use TanStack Query effectively?

TypeScript is not required but strongly recommended. TanStack Query v5 includes first-class TypeScript support with type-safe query keys, strongly typed queryFn arguments, and mutation payloads for better developer experience and fewer runtime errors.

How do I prefetch data and prevent unnecessary requests across components?

Use prefetchQuery to load data before user interaction, and share queryKey across components so TanStack Query deduplicates requests. Configure refetch behavior with staleTime and refetchOnWindowFocus to control when data updates automatically.