jotai vs mobx-react-lite vs react-query vs recoil vs redux vs zustand
State Management and Data Fetching Solutions for React Applications
jotaimobx-react-litereact-queryrecoilreduxzustandSimilar Packages:

State Management and Data Fetching Solutions for React Applications

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.

Npm Package Weekly Downloads Trend

3 Years

Github Stars Ranking

Stat Detail

Package
Downloads
Stars
Size
Issues
Publish
License
jotai021,043519 kB52 days agoMIT
mobx-react-lite028,185424 kB865 months agoMIT
react-query048,7792.26 MB1753 years agoMIT
recoil019,5222.21 MB3223 years agoMIT
redux061,442290 kB432 years agoMIT
zustand057,33295 kB5a month agoMIT

State Management & Data Fetching in React: Jotai vs MobX vs React Query vs Recoil vs Redux vs Zustand

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.

🧠 Core Philosophy: Mutable vs Immutable vs Server-Centric

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>;
};

📦 Setup & Boilerplate: How Much Code Do You Write?

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>
  );
}

🔁 Derived State: Computing from Existing State

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.

🌐 Async Data: Fetching, Caching, and Mutations

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:

  • Automatic refetching on window focus
  • Stale-while-revalidate caching
  • Pagination and infinite queries
  • Optimistic updates and rollback

None of the local state managers do this out of the box.

🚀 Performance: Re-rendering and Granularity

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.

🔄 Server State vs Local State: A Critical Distinction

This is the biggest architectural decision:

  • Use react-query (or similar like SWR) for server state: anything from an API, database, or external service.
  • Use 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.

🧪 Testing and Debugging

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.

📌 When to Combine Libraries

It’s common — and recommended — to combine react-query with a local state manager:

  • Use react-query for user profiles, posts, products, etc.
  • Use 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 });

⚠️ Maintenance and Ecosystem Notes

  • 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.

🆚 Summary Table

LibraryBest ForProvider Needed?Async Built-in?Granular UpdatesLearning Curve
reduxPredictable, debuggable stateYesNoWith selectorsMedium
mobx-react-liteMutable OOP stateNoNoYesMedium
zustandSimple, hook-based global stateNoNoYes (slices)Low
jotaiAtomic, composable stateNo (basic)NoYesLow-Medium
recoilReact-native atoms/selectorsRecommendedNoYesMedium
react-queryServer data fetching & cachingYesYesYesLow-Medium

💡 Final Guidance

  • Building a data-heavy app with lots of APIs? Start with react-query + zustand.
  • Need strict state audit trails or middleware? Go with redux.
  • Prefer writing mutable classes? mobx-react-lite fits naturally.
  • Want minimal setup with atomic thinking? jotai is elegant and scalable.
  • Working on a new project and unsure? 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.

How to Choose: jotai vs mobx-react-lite vs react-query vs recoil vs redux vs zustand

  • jotai:

    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.

  • mobx-react-lite:

    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.

  • react-query:

    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.

  • recoil:

    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.

  • redux:

    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.

  • zustand:

    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.

README for jotai


Jotai (light mode)


visit jotai.org or npm i jotai

Build Status Build Size Version Downloads Discord Shield Open Collective

Jotai scales from a simple useState replacement to an enterprise TypeScript application.

  • Minimal core API (2kb)
  • Many utilities and extensions
  • No string keys (compared to Recoil)

Examples: Demo 1 | Demo 2

First, create a primitive atom

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 })

Use the atom in your components

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>
      ...

Create derived atoms with computed values

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>
}

Creating an atom from multiple atoms

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))

Derived async atoms needs suspense

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)
  ...

You can create a writable derived atom

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>
      ...

Write only derived atoms

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>
}

Async actions

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>
    ...

Note about functional programming

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.

Links