tanstack-query

Apply TanStack Query v5 techniques to manage server-state in React applications.

Updated Feb 7, 2026
One-click install
npx skills add https://github.com/rieckt/create-loumi-app --skill tanstack-query-rieckt
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: tanstack-query
Source: https://github.com/rieckt/create-loumi-app/tree/main/template/skills/convex/tanstack-query
Command: npx skills add https://github.com/rieckt/create-loumi-app --skill tanstack-query-rieckt

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes scripts (resource) and references (resource) and assets (resource) components.

What problem does it solve?

This Skill helps developers manage server-state in React applications using TanStack Query v5, addressing migration hurdles and complex data-fetching patterns.

Core Features & Use Cases

  • useMutationState, simplified optimistic updates, and robust mutation flows
  • Network mode (offline/PWA) and live data handling with refetch strategies
  • infiniteQueryOptions and advanced infinite-query patterns
  • Migration guidance for v4→v5: object syntax, gcTime, isPending, keepPreviousData
  • Debug SSR/hydration scenarios and prefetching patterns

Quick Start

Install TanStack Query v5 and set up a QueryClient:

  • npm install @tanstack/react-query@latest
  • Create a single, shared QueryClient and wrap your app with QueryClientProvider
  • Migrate existing useQuery/useMutation calls to the v5 object syntax and apply the migration tips for gcTime, isPending, initialPageParam, and placeholderData.

Frequently Asked Questions about tanstack-query

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

FAQPage Schema
How do I migrate React Query v4 to TanStack Query v5 object syntax?

To migrate React Query v4 to TanStack Query v5, update your useQuery and useMutation calls to the new object syntax, replace cacheTime with gcTime, use isPending instead of isLoading, and swap keepPreviousData for placeholderData. The queryOptions factory pattern helps centralize reusable configurations during migration.

What is the best way to handle server-side rendering and hydration with TanStack Query?

Handling SSR hydration with TanStack Query involves creating a shared QueryClient server-side, prefetching data into its cache, and passing the dehydrated state to the client. This approach populates server-state before React hydration, preventing client-side refetches and waterfalls.

How do I implement optimistic updates and useMutationState in React server state?

Implement optimistic updates by applying cache changes immediately before the mutation resolves, rolling back on error. TanStack Query v5 uses useMutationState to track and access mutation states across components, ensuring robust mutation flows and responsive UI feedback.

Does TanStack Query support offline network modes for PWA data fetching?

Yes, TanStack Query supports offline network modes for PWA data fetching. Configuring network mode settings allows your React application to pause refetch strategies and mutations when offline, handling live data gracefully and resuming synchronization when connectivity returns.

How do I configure infinite queries using infiniteQueryOptions in TanStack v5?

Configuring infinite queries in TanStack v5 involves using the infiniteQueryOptions factory to define queryKey, queryFn, and initialPageParam. This pattern standardizes infinite data fetching configurations, making them reusable across components for paginated server-state.