TanStack Query is an asynchronous state management library designed to handle server state operations across multiple JavaScript frameworks. The library provides protocol-agnostic data fetching capabilities that work with REST APIs, GraphQL, promises, and other data sources. It is available in framework-specific implementations including React Query, Solid Query, Svelte Query, and Vue Query, with the core functionality written in TypeScript.
The primary purpose of TanStack Query is to simplify the complex task of managing server state in web applications. It abstracts away the boilerplate typically required for fetching, caching, synchronizing, and updating data from remote sources. The library handles caching strategies including stale-while-revalidate patterns, automatic refetching, and cache invalidation. It supports pagination and infinite scrolling patterns for handling large datasets, allowing developers to implement these common UI patterns without building the logic from scratch.
Beyond basic data fetching, TanStack Query provides mutation handling for server state updates, dependent query management where one query depends on the results of another, and background update capabilities. The library includes prefetching functionality to load data before it is needed, query cancellation to prevent unnecessary network requests, and React Suspense support for frameworks that implement this pattern. Optimistic updates are supported, enabling applications to update the UI immediately while server operations complete in the background.
TanStack Query is part of the larger TanStack ecosystem of libraries that includes routing, form state management, table components, and other utilities. The library is distributed via npm with the core package published as @tanstack/query-core, and framework-specific variants like @tanstack/react-query are available for individual framework implementations.