Jotai and Zustand: Modern Alternatives to Redux

· 5 min

Redux has long been the go-to state management library for React developers. While Redux offers predictability and structure, it also comes with significant boilerplate and a steep learning curve. Recently, two libraries—Jotai and Zustand—have emerged as promising alternatives, simplifying state management by reducing complexity and enhancing productivity.

Let’s dive into why these two libraries are catching attention and how they might fit into your next React project.

What is Jotai?

Jotai is an atomic state management library for React. Inspired by React’s built-in useState, it introduces “atoms” as units of state. Each atom manages its own state independently, ensuring fine-grained control and efficient updates.

Key Features of Jotai:

Practical Example with Jotai:

import { atom, useAtom } from 'jotai';

const countAtom = atom(0);

function Counter() {
  const [count, setCount] = useAtom(countAtom);

  return (
    <div>
      <p>{count}</p>
      <button onClick={() => setCount((c) => c + 1)}>
        Increment
      </button>
    </div>
  );
}

This concise approach removes Redux’s action creators and reducers, simplifying your state logic significantly.

What is Zustand?

Zustand (German for “state”) offers a minimalist global state management solution. It provides a centralized store without context providers or Redux-like boilerplate.

Key Features of Zustand:

Practical Example with Zustand:

import { create } from 'zustand';

const useStore = create((set) => ({
  count: 0,
  increment: () => set((state) => ({ count: state.count + 1 })),
}));

function Counter() {
  const count = useStore((state) => state.count);
  const increment = useStore((state) => state.increment);

  return (
    <div>
      <p>{count}</p>
      <button onClick={increment}>Increment</button>
    </div>
  );
}

Again, no need for Redux providers, actions, or dispatchers—just straightforward state updates.

Comparing Jotai, Zustand, and Redux

FeatureJotaiZustandRedux
ComplexityMinimalMinimalHigh (boilerplate)
API StyleAtomic, hook-basedSimple global storeActions & reducers
MiddlewareLimitedBuilt-in supportExtensive
Learning CurveEasyEasySteep
PerformanceFine-grained updatesSelective updatesRequires optimization

Both Jotai and Zustand significantly reduce the boilerplate compared to Redux, offering more intuitive state management aligned closely with React’s philosophy.

Real-World Use Cases

Jotai is Ideal When:

Example Scenario: A complex UI dashboard with multiple independent widgets that each track their own state, such as toggles, forms, and counters. Each widget uses its own atom, updating individually without causing unnecessary re-renders elsewhere.

Zustand Shines When:

Example Scenario: An e-commerce app that manages global cart states, authentication, and theme preferences. Zustand centralizes these states effortlessly, enabling easy subscription from components and clean updates without Redux-style boilerplate.

Redux Still Makes Sense If:

Migrating from Redux to Jotai or Zustand

Migration from Redux doesn’t have to be daunting. You can gradually replace Redux slices:

Final Thoughts

Both Jotai and Zustand represent modern, lean approaches to state management. They reduce boilerplate significantly, enhance readability, and align perfectly with modern React development practices.

Choosing between these libraries boils down to your project’s specific needs:

In your next React app, try Jotai or Zustand. You might discover your new favorite way to manage state—light, efficient, and developer-friendly.