jotai, mobx-react-lite, recoil, redux, and zustand are state management libraries designed to handle client-side application state in React, each with distinct models for defining, updating, and subscribing to state changes. react-query (now known as @tanstack/react-query) is fundamentally different — it specializes in server-state management, handling data fetching, caching, synchronization, and background updates for remote data. While the others focus on local UI or application state, react-query treats server data as a first-class citizen, reducing the need to manually store API responses in global state.
Managing state in React apps isn’t one-size-fits-all. Some libraries handle local UI state, others manage server data, and a few blur the lines. Let’s compare how each package approaches core challenges — with real code examples.
redux enforces immutable state with explicit actions and reducers. Every change must go through a pure function.
// redux (with Redux Toolkit)
import { createSlice } from '@reduxjs/toolkit';
const counterSlice = createSlice({
name: 'counter',
initialState: { value: 0 },
reducers: {
increment: (state) => {
state.value += 1; // Immer allows "mutable" syntax
}
}
});
mobx-react-lite embraces mutable state. You mark objects as observable, and MobX tracks changes automatically.
// mobx-react-lite
import { makeAutoObservable } from 'mobx';
import { observer } from 'mobx-react-lite';
class CounterStore {
count = 0;
constructor() { makeAutoObservable(this); }
increment() { this.count++; }
}
const store = new CounterStore();
const Counter = observer(() => <div>{store.count}</div>);
zustand, jotai, and recoil use immutable updates but expose simpler APIs. They treat state as a black box updated via setters.
// zustand
import { create } from 'zustand';
const useStore = create((set) => ({
count: 0,
increment: () => set((state) => ({ count: state.count + 1 }))
}));
// jotai
import { atom, useAtom } from 'jotai';
const countAtom = atom(0);
const Counter = () => {
const [count, setCount] = useAtom(countAtom);
return <div onClick={() => setCount(c => c + 1)}>{count}</div>;
};
// recoil
import { atom, useRecoilState } from 'recoil';
const countAtom = atom({ key: 'count', default: 0 });
const Counter = () => {
const [count, setCount] = useRecoilState(countAtom);
return <div onClick={() => setCount(c => c + 1)}>{count}</div>;
};
react-query doesn’t manage local state at all. It focuses on server state: fetching, caching, and synchronizing data from APIs.
// react-query
import { useQuery, useMutation } from '@tanstack/react-query';
const UserProfile = ({ userId }) => {
const { data, isLoading } = useQuery({
queryKey: ['user', userId],
queryFn: () => fetchUser(userId)
});
const mutation = useMutation({
mutationFn: updateUser,
onSuccess: () => queryClient.invalidateQueries(['user', userId])
});
if (isLoading) return <div>Loading...</div>;
return <div>{data.name}</div>;
};
redux requires the most setup: store configuration, slices, and often a provider wrapper.
// redux setup
import { configureStore } from '@reduxjs/toolkit';
import counterReducer from './counterSlice';
const store = configureStore({ reducer: { counter: counterReducer } });
// In App.js
<Provider store={store}><Counter /></Provider>
mobx-react-lite needs class or object stores and observer on every component.
// mobx setup
// No provider needed, but every component must be observer()
zustand needs no provider — just call the hook anywhere.
// zustand usage
const count = useStore(state => state.count);
jotai and recoil also avoid top-level providers in basic usage, though recoil recommends <RecoilRoot> for advanced features.
// jotai: no provider needed for basic atoms
// recoil: <RecoilRoot> required in app root
react-query requires a QueryClient and QueryClientProvider.
// react-query setup
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
const queryClient = new QueryClient();
function App() {
return (
<QueryClientProvider client={queryClient}>
<UserProfile userId={1} />
</QueryClientProvider>
);
}
redux uses reselect or RTK’s createSelector.
// redux derived state
import { createSelector } from '@reduxjs/toolkit';
const selectCount = (state) => state.counter.value;
const selectIsEven = createSelector(
[selectCount],
(count) => count % 2 === 0
);
mobx-react-lite uses computed getters.
// mobx computed
get isEven() { return this.count % 2 === 0; }
zustand computes inline or via subscribeWithSelector middleware.
// zustand derived
const isEven = useStore(state => state.count % 2 === 0);
jotai and recoil have first-class derived atoms/selectors.
// jotai derived
const isEvenAtom = atom((get) => get(countAtom) % 2 === 0);
// recoil derived
const isEvenSelector = selector({
key: 'isEven',
get: ({ get }) => get(countAtom) % 2 === 0
});
react-query doesn’t handle derived local state — pair it with another library.
Only react-query is built for this. The others require manual integration with useEffect or custom logic.
// Without react-query (e.g., in zustand)
const useStore = create((set) => ({
user: null,
fetchUser: async (id) => {
const user = await api.getUser(id);
set({ user });
}
}));
// With react-query
const { data } = useQuery({ queryKey: ['user', id], queryFn: () => api.getUser(id) });
react-query handles:
None of the local state managers do this out of the box.
mobx-react-lite and react-query offer the finest granularity — only components using changed observables or query keys re-render.
redux can cause unnecessary re-renders without React.memo or proper selector usage.
zustand lets you subscribe to specific state slices, avoiding full-store re-renders.
// zustand selective subscription
const count = useStore(state => state.count); // Only re-renders when count changes
jotai and recoil automatically optimize based on atom dependencies — if a component only reads countAtom, it won’t re-render when unrelated atoms change.
This is the biggest architectural decision:
react-query (or similar like SWR) for server state: anything from an API, database, or external service.zustand, jotai, redux, etc. for local state: UI toggles, form inputs, client-only calculations.Mixing server data into local state stores leads to cache invalidation bugs, stale data, and manual refetching logic. react-query solves this by treating server state as ephemeral and managed externally.
redux has the best tooling: Redux DevTools let you inspect every action, rewind state, and export logs.
mobx-react-lite works with MobX DevTools for tracking observables.
recoil offers a DevTools extension for time-travel debugging.
zustand and jotai rely on standard React DevTools — simpler but less powerful.
react-query includes a DevTools panel showing query status, cache, and mutations.
It’s common — and recommended — to combine react-query with a local state manager:
react-query for user profiles, posts, products, etc.zustand or jotai for theme settings, modal visibility, or form drafts.Example combo:
// Global store for UI state
const useUIStore = create((set) => ({
darkMode: false,
toggleDarkMode: () => set(state => ({ darkMode: !state.darkMode }))
}));
// Server data via react-query
const { data: user } = useQuery({ queryKey: ['user'], queryFn: fetchUser });
redux is mature, stable, and widely adopted. Redux Toolkit is the modern standard.mobx-react-lite is actively maintained and pairs with MobX 6+.react-query (TanStack Query) is under active development with v5+ releases.recoil is still usable but has seen reduced activity from Meta; evaluate long-term support.jotai and zustand are actively developed with strong community adoption.| Library | Best For | Provider Needed? | Async Built-in? | Granular Updates | Learning Curve |
|---|---|---|---|---|---|
redux | Predictable, debuggable state | Yes | No | With selectors | Medium |
mobx-react-lite | Mutable OOP state | No | No | Yes | Medium |
zustand | Simple, hook-based global state | No | No | Yes (slices) | Low |
jotai | Atomic, composable state | No (basic) | No | Yes | Low-Medium |
recoil | React-native atoms/selectors | Recommended | No | Yes | Medium |
react-query | Server data fetching & caching | Yes | Yes | Yes | Low-Medium |
react-query + zustand.redux.mobx-react-lite fits naturally.jotai is elegant and scalable.zustand is the safest, simplest default for local state.Remember: server state is not your state. Let react-query handle the network, and keep your local state focused on the UI.
Choose jotai if you want a minimal, atomic model that scales from simple to complex state without boilerplate. It’s ideal when you prefer composing small, independent pieces of state (atoms) and deriving values via pure functions (selectors), all while leveraging React’s reactivity natively. Its zero-config setup and TypeScript support make it great for teams valuing simplicity and composability.
Choose mobx-react-lite if your team already uses MobX or prefers mutable state with automatic reactivity. It works best when you have domain models that naturally fit observable objects and want fine-grained updates without manual selector definitions. Note that it requires using observer on components and careful structuring to avoid performance pitfalls.
Choose react-query when your app heavily relies on asynchronous data from APIs. It eliminates manual cache management, provides built-in features like background refetching, pagination, and mutations, and ensures your UI stays in sync with server state. Avoid using it for local UI state — pair it with a local state manager instead.
Choose recoil if you want a React-native feel with atoms and selectors that support async dependencies and time-travel debugging. It’s well-suited for apps needing derived state with complex dependencies or concurrent rendering compatibility. However, note that its development pace has slowed, and adoption in new projects should consider long-term maintenance.
Choose redux if you need strict predictability, time-travel debugging, middleware extensibility (like Redux Toolkit), or are working in a large codebase where explicit state transitions and dev tools are critical. Modern Redux with createSlice reduces boilerplate significantly, but it still requires more setup than newer alternatives.
Choose zustand for a lightweight, hook-based store that avoids provider wrappers and works out of the box with SSR. It’s perfect for medium-sized apps needing a single source of truth without Redux’s ceremony, offering direct state access, middleware support, and easy persistence integration. Its simplicity makes it a strong default choice for many teams.

visit jotai.org or npm i jotai
Jotai scales from a simple useState replacement to an enterprise TypeScript application.
An atom represents a piece of state. All you need is to specify an initial value, which can be primitive values like strings and numbers, objects, and arrays. You can create as many primitive atoms as you want.
import { atom } from 'jotai'
const countAtom = atom(0)
const countryAtom = atom('Japan')
const citiesAtom = atom(['Tokyo', 'Kyoto', 'Osaka'])
const mangaAtom = atom({ 'Dragon Ball': 1984, 'One Piece': 1997, Naruto: 1999 })
It can be used like React.useState:
import { useAtom } from 'jotai'
function Counter() {
const [count, setCount] = useAtom(countAtom)
return (
<h1>
{count}
<button onClick={() => setCount((c) => c + 1)}>one up</button>
...
A new read-only atom can be created from existing atoms by passing a read
function as the first argument. get allows you to fetch the contextual value
of any atom.
const doubledCountAtom = atom((get) => get(countAtom) * 2)
function DoubleCounter() {
const [doubledCount] = useAtom(doubledCountAtom)
return <h2>{doubledCount}</h2>
}
You can combine multiple atoms to create a derived atom.
const count1 = atom(1)
const count2 = atom(2)
const count3 = atom(3)
const sum = atom((get) => get(count1) + get(count2) + get(count3))
Or if you like fp patterns ...
const atoms = [count1, count2, count3, ...otherAtoms]
const sum = atom((get) => atoms.map(get).reduce((acc, count) => acc + count))
You can make the read function an async function too.
const urlAtom = atom('https://json.host.com')
const fetchUrlAtom = atom(async (get) => {
const response = await fetch(get(urlAtom))
return await response.json()
})
function Status() {
// Re-renders the component after urlAtom is changed and the async function above concludes
const [json] = useAtom(fetchUrlAtom)
...
Specify a write function at the second argument. get will return the current
value of an atom. set will update the value of an atom.
const decrementCountAtom = atom(
(get) => get(countAtom),
(get, set, _arg) => set(countAtom, get(countAtom) - 1)
)
function Counter() {
const [count, decrement] = useAtom(decrementCountAtom)
return (
<h1>
{count}
<button onClick={decrement}>Decrease</button>
...
Just do not define a read function.
const multiplyCountAtom = atom(null, (get, set, by) =>
set(countAtom, get(countAtom) * by),
)
function Controls() {
const [, multiply] = useAtom(multiplyCountAtom)
return <button onClick={() => multiply(3)}>triple</button>
}
Just make the write function an async function and call set when you're ready.
const fetchCountAtom = atom(
(get) => get(countAtom),
async (_get, set, url) => {
const response = await fetch(url)
set(countAtom, (await response.json()).count)
}
)
function Controls() {
const [count, compute] = useAtom(fetchCountAtom)
return (
<button onClick={() => compute('http://count.host.com')}>compute</button>
...
Jotai's fluid interface is no accident — atoms are monads, just like promises! Monads are an established pattern for modular, pure, robust and understandable code which is optimized for change. Read more about Jotai and monads.