PACKAGE · DATA FETCHING

@tanstack/react-query

Hooks for managing, caching and syncing asynchronous and remote data in React

WEEKLY DOWNLOADS 28.8M
STARS 49.6K
FORKS 3.9K
OPEN ISSUES 171
GZIP SIZE 16.6 kB
UNPACKED SIZE 858.9 kB
LAST UPDATED 3mo ago
DOWNLOAD TRENDS

@tanstack/react-query downloads — last 12 months

Download trends for @tanstack/react-query1 download series from Jun 2025 to May 2026. Use left and right arrow keys to inspect monthly values.058.0M115.9M173.9M231.8MJun 2025SepDecMarMay 2026
@tanstack/react-query
ABOUT @TANSTACK/REACT-QUERY

TanStack Query (formerly React Query) is a powerful data-fetching and state management library for JavaScript applications. It addresses the common complexities of asynchronous data, such as caching, synchronization, background updates, and error handling. By abstracting these concerns, it allows developers to focus on building user interfaces rather than managing the intricacies of data fetching.

The core philosophy of TanStack Query revolves around declarative data management. It treats asynchronous data as server state, distinct from client state, and provides tools to manage its lifecycle efficiently. This approach is particularly beneficial for applications that interact heavily with remote APIs, making it a popular choice for modern single-page applications built with React and its ecosystem.

Key to its functionality are the `useQuery` and `useMutation` hooks. `useQuery` declaratively fetches data based on a unique query key and automatically handles caching, background refetching, and stale-while-revalidate strategies. `useMutation` manages the lifecycle of asynchronous mutations, including states like loading, error, and success, simplifying data updates and invalidations.

TanStack Query integrates seamlessly with React. It's framework-agnostic in its core but offers specific bindings for React, making it a natural fit for any React project. Its design also supports other frameworks like Solid, Vue, and Svelte through separate packages, showcasing its versatility and broad applicability within the modern web development landscape.

With a minimal bundle size of 16.6 kB (gzipped) and a reported unpacked size of 858.9 kB, its performance is a key strength. The library's mature design, evidenced by its 49.6K GitHub stars and frequent updates, ensures stability and reliability for complex applications, despite 165 open issues indicating ongoing development.

While highly capable, TanStack Query abstracts away much of the direct request lifecycle. Developers intending to perform highly specific, low-level network control or manual request management might find its abstractions require adaptation. It's also primarily designed for managing server state, not client-side UI state, which usually requires separate state management solutions.

WHEN TO USE
  • When managing complex, asynchronous data fetching and caching for remote data sources in React applications.
  • When needing to automatically refetch data in the background, such as on window focus or interval, using capabilities like `stale-while-revalidate`.
  • When implementing sophisticated data mutation and invalidation patterns with the `useMutation` hook to reflect server-side changes in the UI.
  • When building applications that require robust loading, error, and success state management for asynchronous operations declaratively.
  • When integrating with REST or GraphQL APIs and needing a unified approach to handle their data lifecycles alongside client-side state.
  • When aiming to reduce boilerplate code associated with manual request management, caching, and state synchronization for server data.
WHEN NOT TO USE
  • If your application primarily deals with simple, synchronous UI state — React's built-in `useState` and `useContext` may suffice.
  • If you require manual control over every aspect of the HTTP request and response cycle without abstraction.
  • When solely managing purely client-side state that never interacts with a remote server, other state management tools might be lighter.
  • If you are working within a very limited environment where even a 16.6 kB (gzipped) bundle size is prohibitive.
  • When embarking on a project where strict immutability and manual state merging are enforced, and the caching mechanisms of TanStack Query introduce complexity.

CORRECTIONS

Spot wrong data here?

A short note helps us fix it.

Anonymous · No account · No email back

COMPARISONS 2
@tanstack/react-query vs swr ★ 32.4K · 5.8M/wk @tanstack/react-query vs apollo-client ★ 19.7K · 233.7K/wk