Skip to main content

State Management

note

Recoil is no longer maintained (last release 0.7.7 in March 2023; the repo was archived in 2025) - prefer Jotai (similar atom model) or Zustand for new projects.

FeatureReact ContextZustandJotaiRecoilReduxMobX
ComplexityLowLowLowMediumHighHigh
Learning CurveEasyEasyEasyModerateSteepSteep
State ManagementSimpleSimpleSimpleComplexComplexComplex
Boilerplate CodeMinimalMinimalMinimalModerateHighHigh
DevTools SupportLimitedGoodGoodGoodExcellentGood
Middleware SupportNoNoNoYesYesYes
Asynchronous ActionsNoYesYesYesYesYes

Summary​

  • All techs have good performance & support typeScript
  • Community & Ecosystem
    • Large (Redux, MobX)
    • Growing (Zustand, Jotai, Recoil)
  • Documentation
    • Good (React Context, Zustand, Jotai, Recoil, MobX)
    • Excellent (Redux)
  • Use Cases
    • Simple (React Context, Zustand, Jotai)
    • Complex (Recoil, Redux, MobX)

Side by side​

The Redux family covered in this folder, with the same counter in each approach and one data fetch in RTK Query. Immer is the helper that makes the "mutating" reducer style safe, so its tab shows the same counter with plain React state.

A hand-written reducer, store and hooks (core Redux's createStore is deprecated, so the store is built with configureStore).

import { configureStore } from "@reduxjs/toolkit";
import { Provider, useDispatch, useSelector } from "react-redux";

type Action = { type: "increment" } | { type: "decrement" };

function counter(state = { value: 0 }, action: Action) {
switch (action.type) {
case "increment":
return { ...state, value: state.value + 1 };
case "decrement":
return { ...state, value: state.value - 1 };
default:
return state;
}
}

const store = configureStore({ reducer: { counter } });

function Counter() {
const count = useSelector((state: any) => state.counter.value);
const dispatch = useDispatch();
return (
<div>
<button onClick={() => dispatch({ type: "decrement" })}>-</button>
<span>{count}</span>
<button onClick={() => dispatch({ type: "increment" })}>+</button>
</div>
);
}

// <Provider store={store}><Counter /></Provider>

Source: React Redux hooks. Full note: React Redux.