@tanstack/react-query

v5.96.2 MIT

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

Weekly Downloads
28.5M
Stars
49.0K
Forks
3.8K
Open Issues
161
Gzip Size
16.9 kB
Unpacked Size
858.6 kB
Dependencies
3
Last Updated
1mo ago

@tanstack/react-query Download Trends

Download trends for @tanstack/react-query032.3M64.5M96.8M129.1MFeb 2025MayAugNovFebApr 2026
@tanstack/react-query

About @tanstack/react-query

React Query, now known as Tanstack Query, solves the complex problem of managing asynchronous server state in React applications. It provides hooks to fetch, cache, synchronize, and update data from remote APIs, thereby eliminating many of the boilerplate and state management challenges associated with data fetching.

The core philosophy revolves around declarative data fetching and intelligent caching, treating server state just like client state. This approach simplifies development by abstracting away manual caching, background updates, and request deduplication, making it ideal for developers building interactive applications that rely heavily on remote data.

Key APIs like `useQuery` and `useMutation` form the foundation of its usage. `useQuery` automatically handles fetching, caching, and background refetching of data based on a unique query key. `useMutation` simplifies the process of creating, updating, or deleting data on the server, also with built-in caching and optimistic update capabilities.

Tanstack Query seamlessly integrates within the React ecosystem. It's framework-agnostic at its core, but its primary bindings, `@tanstack/react-query`, are tailored for React. It also offers bindings for other frameworks like Solid, Vue, and Svelte, facilitating a consistent data-fetching experience across different UI technologies.

With a weekly download count exceeding 39.7 million and 49.0K GitHub stars, Tanstack Query is a mature and widely adopted solution. Its efficient caching mechanisms and focus on minimizing unnecessary network requests contribute to improved application performance. The library's unpacked size is 858.6 kB, with a gzipped bundle size of only 16.9 kB, making it a relatively lightweight addition to your project.

While powerful, developers should be aware that Tanstack Query's strength lies in managing server state. For purely client-side state management that doesn't involve remote data, using React's built-in `useState` or `useReducer` hooks, potentially combined with context, might be a simpler alternative. Complex configurations for specific offline scenarios might also require custom logic beyond the library's default caching behaviors.

When to use

  • When managing the fetching, caching, and synchronization of remote data using hooks like `useQuery` and `useMutation`.
  • When implementing background data refetching and stale-while-revalidate strategies to keep UI data fresh.
  • When simplifying complex data mutation flows with features like optimistic updates and error handling via `useMutation`.
  • When deduplicating identical requests to the same endpoint within a short timeframe.
  • When integrating with frameworks beyond React, leveraging its core capabilities with adapters for Solid, Vue, or Svelte.
  • When building applications that require a sophisticated caching layer to improve perceived performance and reduce server load.
  • When dealing with paginated, infinite, or cursor-based data loading patterns.

When NOT to use

  • If you only need to manage simple local component state — React's built-in `useState` hook is sufficient and avoids adding external dependencies.
  • If your primary need is managing global client-side state without any remote data interactions — a dedicated state management library for client state might offer a more streamlined API.
  • If you require a solution that strictly avoids all forms of client-side caching for remote data — manual fetch implementations would be necessary.
  • If your application has extremely minimal data fetching needs and no caching requirements — the overhead of integrating Tanstack Query might not be justified.
  • If you are working in an environment where only basic `fetch` or `XMLHttpRequest` APIs are permitted without any abstraction.

@tanstack/react-query Alternatives

@tanstack/react-query Categories