tanstack-query

Implement server state management in React with TanStack Query v5 patterns and migration fixes.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

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

What problem does it solve? React developers migrating from TanStack Query v4 to v5 hit breaking changes like removed query callbacks, renamed options (cacheTime to gcTime), and changed loading state semantics, while SSR hydration mismatches and optimistic update patterns remain hard to debug without version-specific guidance. ## Core Features & Use Cases - v5 Migration & Error Prevention: Documents 16 known issues including object syntax requirements, isPending vs isLoading semantics, initialPageParam requirements, and mutation callback signature changes, each with before/after code fixes. - Modern v5 Patterns: Covers useMutationState for cross-component mutation tracking, simplified optimistic updates without cache rollback, network modes for offline/PWA support, and infiniteQueryOptions with maxPages memory limits. - Production Templates & References: Provides ready-to-use QueryClient configuration, provider setup, error boundary components, custom hooks patterns, testing guides with MSW, and TypeScript patterns including Zod validation. - Use Case: When a Next.js app throws hydration errors after adding server-side prefetching, consult the known issues section to find the exact workaround (use useSuspenseQuery or await prefetch) instead of debugging for hours. ## Quick Start Ask the assistant to set up TanStack Query v5 in your React project with a configured QueryClient, provider, and a typed query hook for your API endpoint.

Frequently Asked Questions about tanstack-query

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

FAQPage Schema
How do I migrate TanStack Query from v4 to v5?

Migrate to v5 by switching all hooks to object syntax, replacing cacheTime with gcTime, using isPending instead of isLoading for initial loads, and moving query onSuccess callbacks into useEffect. Infinite queries also require an explicit initialPageParam option.

Why is isLoading not working in TanStack Query v5?

In v5, isLoading now means isPending AND isFetching, so it behaves differently than v4. Use isPending to detect the initial loading state when no data exists yet, which matches the old v4 isLoading behavior.

How do I fix hydration errors with TanStack Query and Next.js?

Hydration errors with server-side prefetching occur because useQuery can resolve synchronously during hydration. Use useSuspenseQuery instead of useQuery for SSR, or await the prefetch call rather than using the void prefetch pattern.

Does TanStack Query v5 support optimistic updates?

Yes, v5 supports both traditional cache-manipulation optimistic updates with onMutate rollback and a simplified pattern using useMutationState to render pending mutation variables directly. The simplified approach requires no cache manipulation or rollback logic.

Why did my mutation callbacks break after upgrading to v5.89?

Version 5.89.0 added an onMutateResult parameter between variables and context in mutation callbacks, changing signatures from three to four parameters. Update onSuccess and onError callbacks to accept (data, variables, onMutateResult, context).

When should I not use TanStack Query?

Do not use TanStack Query for client-only state like modal visibility or form inputs; use useState or a client state library instead. It is designed specifically for server state that lives on a remote API and needs caching, deduplication, and synchronization.