TanStack Query vs SWR
Which should you use? A side-by-side look at what each one does, who it suits, what it costs, how hard it is to set up, and where each falls short.
Open source · MIT
A library for fetching, caching, and updating data from servers in web apps.
Open source · MIT
A React hook library for fetching data, with caching and automatic refresh.
The short answer
Choose TanStack Query if you need…
- Frontend developers building apps that load data from a server
- Teams using React, Solid, Svelte, or Vue who want less hand-written loading and caching code
- Apps that need pagination, infinite scroll, or background refresh of data
Choose SWR if you need…
- React developers who fetch data from APIs in components
- Projects that want built-in caching and request deduplication
- Apps that need data to refresh on focus, network recovery, or polling
- Teams building React Native or Next.js interfaces
Side-by-side
| TanStack Query | SWR | |
|---|---|---|
| Type | Library | Library |
| Price | Free and open source | Free and open source |
| Licence | MIT | MIT |
| GitHub stars | 50.5k | 32.5k |
| Setup difficulty | Intermediate | Intermediate |
| How you get it | Install with a package manager | Install with a package manager |
| Main language | TypeScript | TypeScript |
| Last code update | 4 days ago | 20 days ago |
What each one is
TanStack Query
TanStack Query is an open-source library for managing server data in web apps. It handles fetching data from an API, caching the results, keeping them in sync, and updating them after changes. The README says it works with REST, GraphQL, or any promise-based fetching, and it has versions for React, Solid, Svelte, and Vue.
SWR
SWR is a React Hooks library for loading data in web interfaces. Its name comes from stale-while-revalidate: it shows cached data first, requests fresh data in the background, then updates the screen when the new data arrives. Developers use it to simplify data loading logic in React components.
Best for
TanStack Query
- Frontend developers building apps that load data from a server
- Teams using React, Solid, Svelte, or Vue who want less hand-written loading and caching code
- Apps that need pagination, infinite scroll, or background refresh of data
SWR
- React developers who fetch data from APIs in components
- Projects that want built-in caching and request deduplication
- Apps that need data to refresh on focus, network recovery, or polling
- Teams building React Native or Next.js interfaces
Strengths
TanStack Query
- Covers fetching, caching, refetching, and mutations in one library
- Works with multiple frameworks and any promise-based or GraphQL data source
- Large community: about 50,000 GitHub stars and an MIT license
SWR
- Small, focused API: one hook covers the common fetch, loading, and error cases
- Built-in cache and request deduplication reduce repeated network calls
- Works with any asynchronous fetcher, so you can use your preferred fetching library
Not ideal for
TanStack Query
- People who only need a simple static site with no server data (the library adds complexity without benefit)
- Non-developers looking for a ready-made app (this is a code library, not an end-user tool)
SWR
- People who do not write React code, since the library is built around React Hooks
- Projects that need a full server-side data layer rather than client-side fetching hooks
- Beginners with no JavaScript or React experience, who would need to learn those first
Trade-offs
TanStack Query
- Requires learning its concepts (queries, mutations, cache keys) before it is productive
- The README is truncated here, so detailed setup and API behavior are not covered in this entry
SWR
- Requires React knowledge; it is not useful outside React-style apps
- The README is brief and points to the external documentation site for details and examples
- Behavior such as caching and revalidation has settings that take time to learn
Getting started
TanStack Query
Clone the repository
git clone https://github.com/TanStack/queryFrequently asked questions
What is the difference between TanStack Query and SWR?
TanStack Query: A library for fetching, caching, and updating data from servers in web apps. SWR: A React hook library for fetching data, with caching and automatic refresh. TanStack Query suits frontend developers building apps that load data from a server, while SWR suits react developers who fetch data from apis in components.
Are TanStack Query and SWR free?
TanStack Query: Free and open source. SWR: Free and open source.
Is TanStack Query or SWR more popular?
TanStack Query has more GitHub stars (50.5k) than SWR (32.5k). Popularity isn't the same as fit — check which one matches your use case above.
What are other alternatives to TanStack Query and SWR?
Other options people compare them with include Apollo Client, ky, why-did-you-render, react-loadable, Zustand.
Keep comparing
Built from our catalogue entries for both products: open-source details come from each project's README (AI-assisted, refreshed weekly) and GitHub data; AI-tool details are editorial. Spotted something wrong? Let us know from either product's page.