Open History to see the last commit
1---
2id: does-this-replace-client-state
3title: Does React Query replace Redux, MobX or other global state managers?
4---
5β
6Well, let's start with a few important items:
7β
8- React Query is a **server-state** library, responsible for managing asynchronous operations between your server and client
9- Redux, MobX, Zustand, etc. are **client-state** libraries that _can be used to store asynchronous data, albeit inefficiently when compared to a tool like React Query_
10β
11With those points in mind, the short answer is that React Query **replaces the boilerplate code and related wiring used to manage cache data in your client-state and replaces it with just a few lines of code.**
12β
13For a vast majority of applications, the truly **globally accessible client state** that is left over after migrating all of your async code to React Query is usually very tiny.
14β
15> There are still some circumstances where an application might indeed have a massive amount of synchronous client-only state (like a visual designer or music production application), in which case, you will probably still want a client state manager. In this situation it's important to note that **React Query is not a replacement for local/client state management**. However, you can use React Query along side most client state managers with zero issues.
16β
17## A Contrived Example
18β
19Here we have some "global" state being managed by a global state library:
20β
21```js
22const globalState = {
23 projects,
24 teams,
25 tasks,
26 users,
27 themeMode,
28 sidebarStatus,
29}
30```
31β
32Currently, the global state manager is caching 4 types of server-state: `projects`, `teams`, `tasks`, and `users`. If we were to move these server-state assets to React Query, our remaining global state would look more like this:
33β
34```js
35const globalState = {
36 themeMode,
37 sidebarStatus,
38}
39```
40β
41This also means that with a few hook calls to `useQuery` and `useMutation`, we also get to remove any boilerplate code that was used to manage our server state eg.
42β
43- Connectors
44- Action Creators
45- Middlewares
46- Reducers
47- Loading/Error/Result states
48- Contexts
49β
50With all of those things removed, you may ask yourself, **"Is it worth it to keep using our client state manager for this tiny global state?"**
51β
52**And that's up to you!**
53β
54But React Query's role is clear. It removes asynchronous wiring and boilerplate from your application and replaces it with just a few lines of code.
55β
56What are you waiting for, give it a go already!