API Reference

TanStack Query

Powerful asynchronous state management for data fetching, caching, and synchronization in React, Vue, Solid and Svelte.

Official Documentation ↗
CompatibilityThis documentation covers version v5.32. Check the official docs for the latest API surface.

Installation

npmnpm install @tanstack/react-query
pnpmpnpm add @tanstack/react-query
yarnyarn add @tanstack/react-query

Methods

TanStack Query is a powerful data-synchronization library that treats server state as a first-class citizen. It handles fetching, caching, background updates, and stale data management automatically, eliminating the boilerplate of manual state management for API data.

Key Features

  • Automatic caching: Deduplicates requests and caches by queryKey
  • Background refetching: Refetches stale data on focus, reconnect, or interval
  • Optimistic updates: Built-in support for optimistic mutations with rollback
  • DevTools: @tanstack/react-query-devtools for cache inspection
  • Framework agnostic: Works with React, Vue, Solid, and Svelte
  • Infinite queries: Built-in support for pagination and infinite scrolling

FAQ

Is TanStack Query a replacement for Redux or Zustand?
No. TanStack Query manages server state (data fetched from APIs), while Redux/Zustand manage client state (UI state, form state). They complement each other and are often used together.
How does automatic caching work?
Each query is cached by its queryKey. When the same key is requested again, cached data is shown immediately while a background refetch occurs if the data is stale. Stale time and cache time are configurable per query.
Does it work outside of React?
Yes. TanStack Query has framework-specific packages for React, Vue, Solid, and Svelte. The core @tanstack/query-core package is framework-agnostic.