pkgdocs/compare/immer vs zustand

Comparing

npm

immer

Create your next immutable state by mutating the current one

41.7M/ wk
v11.1.4
vs
npm

zustand

🐻 Bear necessities for state management in React

30.7M/ wk
v5.0.12
Metricimmerzustand
Ecosystemnpmnpm
DifficultyBeginner ✓Intermediate
Weekly downloads41.7M↑30.7M
Latest versionv11.1.4v5.0.12
Recipes17↑

Tags

immer only

immutablemutationsmutablecopy-on-writetypescriptimmutablesreducer

Shared

statereduxreact

zustand only

state-managementglobal-statehookslightweightmanagermanagementstore

When to use each

immer

Use Immer whenever you have deeply nested state updates that are painful to write immutably: Redux reducers, Zustand's set function, or React useState with complex objects. It's built into Redux Toolkit's createSlice, so you're probably already using it.

zustand

Use Zustand for global UI state that multiple components need to read and write: auth status, theme preferences, shopping cart, modal state, or any data too complex for prop drilling but not complex enough to justify Redux.

When to skip each

immer

For flat, simple state (a counter, a boolean toggle), immer's overhead isn't worth it — just spread the object. Immer also has edge cases with classes, Maps, and Sets that require using enableMapSet() and enableAllPlugins().

zustand

Zustand is not designed for server state — use React Query for that. For very large applications with complex state machines or time-travel debugging requirements, Redux Toolkit's tooling is more mature.

Sample recipes

immer

  • Install immer

zustand

  • Install zustand
  • Introduction
  • Selecting multiple state slices
  • Using zustand without React

+3 more