Open History to see the last commit
1---
2id: comparison
3title: Comparison | React Query vs SWR vs Apollo vs RTK Query vs React Router
4---
5β
6> This comparison table strives to be as accurate and as unbiased as possible. If you use any of these libraries and feel the information could be improved, feel free to suggest changes (with notes or evidence of claims) using the "Edit this page on Github" link at the bottom of this page.
7β
8Feature/Capability Key:
9β
10- β
1st-class, built-in, and ready to use with no added configuration or code
11- π‘ Supported, but as an unofficial 3rd party or community library/contribution
12- πΆ Supported and documented, but requires extra user-code to implement
13- π Not officially supported or documented.
14β
15| | React Query | SWR [_(Website)_][swr] | Apollo Client [_(Website)_][apollo] | RTK-Query [_(Website)_][rtk-query] | React Router [_(Website)_][react-router] |
16| -------------------------------------------------- | ---------------------------------------- | --------------------------- | ------------------------------------------ | ------------------------------------ | ------------------------------------------------------------------------- |
17| Github Repo / Stars | [![][stars-react-query]][gh-react-query] | [![][stars-swr]][gh-swr] | [![][stars-apollo]][gh-apollo] | [![][stars-rtk-query]][gh-rtk-query] | [![][stars-react-router]][gh-react-router] |
18| Platform Requirements | React | React | React, GraphQL | Redux | React |
19| Their Comparison | | (none) | (none) | [Comparison][rtk-query-comparison] | [Comparison][react-router-comparison] |
20| Supported Query Syntax | Promise, REST, GraphQL | Promise, REST, GraphQL | GraphQL | Promise, REST, GraphQL | Promise, REST, GraphQL |
21| Supported Frameworks | React | React | React + Others | Any | React |
22| Caching Strategy | Hierarchical Key -> Value | Unique Key -> Value | Normalized Schema | Unique Key -> Value | Nested Route -> value |
23| Cache Key Strategy | JSON | JSON | GraphQL Query | JSON | Route Path |
24| Cache Change Detection | Deep Compare Keys (Stable Serialization) | Shallow Compare Keys | Deep Compare Keys (Unstable Serialization) | Key Referential Equality (===) | Route Change |
25| Data Change Detection | Deep Comparison + Structural Sharing | Deep Compare (via `dequal`) | Deep Compare (Unstable Serialization) | Key Referential Equality (===) | Loader Run |
26| Data Memoization | Full Structural Sharing | Identity (===) | Normalized Identity | Identity (===) | Identity (===) |
27| Bundle Size | [![][bp-react-query]][bpl-react-query] | [![][bp-swr]][bpl-swr] | [![][bp-apollo]][bpl-apollo] | [![][bp-rtk-query]][bpl-rtk-query] | [![][bp-react-router]][bpl-react-router] + [![][bp-history]][bpl-history] |
28| API Definition Location | Component, External Config | Component | GraphQL Schema | External Config | Route Tree Configuration |
29| Queries | β
| β
| β
| β
| β
|
30| Cache Persistence | β
| β
| β
| β
| π Active Routes Only <sup>8</sup> |
31| Devtools | β
| π‘ | β
| β
| π |
32| Polling/Intervals | β
| β
| β
| β
| π |
33| Parallel Queries | β
| β
| β
| β
| β
|
34| Dependent Queries | β
| β
| β
| β
| β
|
35| Paginated Queries | β
| β
| β
| β
| β
|
36| Infinite Queries | β
| β
| β
| π | π |
37| Bi-directional Infinite Queries | β
| πΆ | πΆ | π | π |
38| Infinite Query Refetching | β
| β
| π | π | π |
39| Lagged Query Data<sup>1</sup> | β
| πΆ | π | β
| β
|
40| Selectors | β
| π | β
| β
| N/A |
41| Initial Data | β
| β
| β
| β
| β
|
42| Scroll Recovery | β
| β
| β
| β
| β
|
43| Cache Manipulation | β
| β
| β
| β
| π |
44| Outdated Query Dismissal | β
| β
| β
| β
| β
|
45| Render Batching & Optimization<sup>2</sup> | β
| π | π | β
| β
|
46| Auto Garbage Collection | β
| π | π | β
| N/A |
47| Mutation Hooks | β
| π‘ | β
| β
| β
|
48| Offline Mutation Support | β
| π | π‘ | π | π |
49| Prefetching APIs | β
| πΆ | β
| β
| β
|
50| Query Cancellation | β
| π | π | π | β
|
51| Partial Query Matching<sup>3</sup> | β
| π | π | β
| N/A |
52| Stale While Revalidate | β
| β
| β
| β
| π |
53| Stale Time Configuration | β
| π<sup>7</sup> | π | β
| π |
54| Pre-usage Query/Mutation Configuration<sup>4</sup> | β
| π | π | β
| β
|
55| Window Focus Refetching | β
| β
| π | πΆ | π |
56| Network Status Refetching | β
| β
| β
| πΆ | π |
57| General Cache Dehydration/Rehydration | β
| π | β
| β
| β
|
58| Offline Caching | β
(Experimental) | π | β
| πΆ | π |
59| React Suspense (Experimental) | β
| β
| π | π | β
|
60| Abstracted/Agnostic Core | β
| π | β
| β
| π |
61| Automatic Refetch after Mutation<sup>5</sup> | πΆ | πΆ | β
| β
| β
|
62| Normalized Caching<sup>6</sup> | π | π | β
| π | π |
63β
64### Notes
65β
66> **<sup>1</sup> Lagged Query Data** - React Query provides a way to continue to see an existing query's data while the next query loads (similar to the same UX that suspense will soon provide natively). This is extremely important when writing pagination UIs or infinite loading UIs where you do not want to show a hard loading state whenever a new query is requested. Other libraries do not have this capability and render a hard loading state for the new query (unless it has been prefetched), while the new query loads.
67β
68> **<sup>2</sup> Render Optimization** - React Query has excellent rendering performance. It will only re-render your components when a query is updated. For example because it has new data, or to indicate it is fetching. React Query also batches updates together to make sure your application only re-renders once when multiple components are using the same query. If you are only interested in the `data` or `error` properties, you can reduce the number of renders even more by setting `notifyOnChangeProps` to `['data', 'error']`. Set `notifyOnChangeProps: 'tracked'` to automatically track which fields are accessed and only re-render if one of them changes.
69β
70> **<sup>3</sup> Partial query matching** - Because React Query uses deterministic query key serialization, this allows you to manipulate variable groups of queries without having to know each individual query-key that you want to match, eg. you can refetch every query that starts with `todos` in its key, regardless of variables, or you can target specific queries with (or without) variables or nested properties, and even use a filter function to only match queries that pass your specific conditions.
71β
72> **<sup>4</sup> Pre-usage Query Configuration** - This is simply a fancy name for being able to configure how queries and mutations will behave before they are used. For instance, a query can be fully configured with defaults beforehand and when the time comes to use it, only `useQuery(key)` is necessary, instead of being required to pass the fetcher and/or options with every usage. SWR does have a partial form of this feature by allowing you to pre-configure a default fetcher, but only as a global fetcher, not on a per-query basis and definitely not for mutations.
73β
74> **<sup>5</sup> Automatic Refetch after Mutation** - For truly automatic refetching to happen after a mutation occurs, a schema is necessary (like the one graphQL provides) along with heuristics that help the library know how to identify individual entities and entities types in that schema.
75β
76> **<sup>6</sup> Normalized Caching** - React Query, SWR and RTK-Query do not currently support automatic-normalized caching which describes storing entities in a flat architecture to avoid some high-level data duplication.
77β
78> **<sup>7</sup> SWR's Immutable Mode** - SWR ships with an "immutable" mode that does allow you to only fetch a query once for the life of the cache, but it still does not have the concept of stale-time or conditional auto-revalidation
79β
80> **<sup>8</sup> React Router cache persistence** - React Router does not cache data beyond the currently matched routes. If a route is left, its data is lost.
81β
82<!-- -->
83β
84[bpl-react-query]: https://bundlephobia.com/result?p=react-query
85[bp-react-query]: https://badgen.net/bundlephobia/minzip/react-query?label=πΎ
86[gh-react-query]: https://github.com/tannerlinsley/react-query
87[stars-react-query]: https://img.shields.io/github/stars/tannerlinsley/react-query?label=%F0%9F%8C%9F
88β
89<!-- -->
90β
91[swr]: https://github.com/vercel/swr
92[bp-swr]: https://badgen.net/bundlephobia/minzip/swr?label=πΎ
93[gh-swr]: https://github.com/vercel/swr
94[stars-swr]: https://img.shields.io/github/stars/vercel/swr?label=%F0%9F%8C%9F
95[bpl-swr]: https://bundlephobia.com/result?p=swr
96β
97<!-- -->
98β
99[apollo]: https://github.com/apollographql/apollo-client
100[bp-apollo]: https://badgen.net/bundlephobia/minzip/@apollo/client?label=πΎ
101[gh-apollo]: https://github.com/apollographql/apollo-client
102[stars-apollo]: https://img.shields.io/github/stars/apollographql/apollo-client?label=%F0%9F%8C%9F
103[bpl-apollo]: https://bundlephobia.com/result?p=@apollo/client
104β
105<!-- -->
106β
107[rtk-query]: https://redux-toolkit.js.org/rtk-query/overview
108[rtk-query-comparison]: https://redux-toolkit.js.org/rtk-query/comparison
109[rtk-query-bundle-size]: https://redux-toolkit.js.org/rtk-query/comparison#bundle-size
110[bp-rtk]: https://badgen.net/bundlephobia/minzip/@reduxjs/toolkit?label=πΎ
111[bp-rtk-query]: https://badgen.net/bundlephobia/minzip/@reduxjs/toolkit?label=πΎ
112[gh-rtk-query]: https://github.com/reduxjs/redux-toolkit
113[stars-rtk-query]: https://img.shields.io/github/stars/reduxjs/redux-toolkit?label=π
114[bpl-rtk]: https://bundlephobia.com/result?p=@reduxjs/toolkit
115[bpl-rtk-query]: https://bundlephobia.com/package/@reduxjs/toolkit
116β
117<!-- -->
118β
119[react-router]: https://github.com/remix-run/react-router
120[bp-react-router]: https://badgen.net/bundlephobia/minzip/react-router-dom?label=πΎ
121[gh-react-router]: https://github.com/remix-run/react-router
122[stars-react-router]: https://img.shields.io/github/stars/remix-run/react-router?label=%F0%9F%8C%9F
123[bpl-react-router]: https://bundlephobia.com/result?p=react-router-dom
124[bp-history]: https://badgen.net/bundlephobia/minzip/history?label=πΎ
125[bpl-history]: https://bundlephobia.com/result?p=history