TanStack Query caches and synchronizes remote data in TypeScript and JavaScript apps. Bindings exist for React, Vue, Solid, Svelte, Angular, and Lit.
Overview
TanStack Query is a library for asynchronous state tied to server data. It coordinates fetching, caching, sharing, refetching, mutating, and observing remote state without adopting a global client store.
Fetching is protocol-agnostic: REST, GraphQL, promises, and other async sources work through the same APIs. Features include deduplicated requests, retries, pagination, infinite queries, dependent queries, background updates, prefetching, cancellation, and React Suspense integration.
Cached entries track freshness, subscribers, and garbage collection after observers unmount. Stale data can stay visible while a background refetch runs. Mutations support optimistic updates, rollback on error, and targeted invalidation.
Devtools help inspect cache entries and query lifecycle during development. The same core ships across multiple UI frameworks under the TanStack Query family.
Key features
- Shared cache across observers
- Stale-while-revalidate refetching
- Mutations with optimistic updates
- Pagination and infinite queries
- Background and focus refetching
- Query invalidation after writes
- Framework-specific bindings
- Devtools for cache inspection
Use cases
- Client apps loading REST or GraphQL APIs
- Reducing duplicate fetch logic in SPAs
- Optimistic UI for create and update flows
- Paginated and infinite list views