tanstack-query

Manage server state and data fetching in React with TanStack Query v5.

278|29|Updated Nov 4, 2025
One-click install
npx skills add https://github.com/MadAppGang/claude-code --skill tanstack-query-madappgang
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: tanstack-query
Source: https://github.com/MadAppGang/claude-code/tree/main/plugins/frontend/skills/tanstack-query
Command: npx skills add https://github.com/MadAppGang/claude-code --skill tanstack-query-madappgang

SYSTEM DOCUMENTATION & REQUIREMENTS

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

What problem does it solve?

Managing asynchronous server state, data fetching, caching, and synchronization in React applications can be complex and error-prone. This Skill provides battle-tested patterns for TanStack Query v5.

Core Features & Use Cases

  • Async State Management: Handle data fetching, caching, background updates, and synchronization automatically.
  • Optimistic Updates: Implement advanced optimistic UI with rollback for a smooth user experience.
  • Type-Safe API: Leverage queryOptions and TypeScript inference for robust and error-free data interactions.
  • Use Case: Implement a "create todo" feature with an optimistic update that instantly shows the new todo in the UI, then rolls back if the API call fails, all while ensuring cache consistency.

Quick Start

Use the tanstack-query skill to implement a useTodosQuery hook for fetching 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 manage server state and data fetching in React with caching?

Data fetching and caching in React is simplified with TanStack Query v5, which handles async state, background synchronization, and automatic cache invalidation. It eliminates manual state management for server data, reducing boilerplate and preventing stale data issues.

How do I implement optimistic updates in React applications?

Optimistic updates in TanStack Query show changes to the UI immediately while the API request completes, then roll back if it fails. This pattern keeps cache consistent and delivers a responsive user experience without waiting for server confirmation.

Can I use TanStack Query with TypeScript for type-safe data fetching?

Yes. TanStack Query v5 supports queryOptions and TypeScript inference to provide end-to-end type safety across queries, mutations, and cache state, catching errors at compile time rather than runtime.

What's the best way to organize query keys and cache structure in TanStack Query?

TanStack Query recommends hierarchical key factories and feature-based colocation to organize queries logically. This approach ensures predictable cache invalidation, prevents key collisions, and keeps related data-fetching logic together with UI components.

How do I test React components that use TanStack Query?

Test TanStack Query hooks with Mock Service Worker (MSW) to intercept API calls and simulate server responses. This decouples tests from live APIs, enables reliable mocking of mutations and error states, and speeds up test execution.

What changed in TanStack Query v5 from earlier versions?

TanStack Query v5 renamed options (cacheTime to gcTime, keepPreviousData to placeholderData), removed per-hook callbacks in favor of global QueryCache callbacks, added first-class suspense support, and introduced initialPageParam for infinite queries.