Zustand is a state-management library for developers building React applications or using stores outside React. A store holds state independently of React; a bound hook lets your components select the values they need without a context provider. Start with state and actions, then add persistence, debugging, or other middleware when your application needs them.
Package and entry points
zustand provides the stores, React bindings, and middleware described below. Install it in your project:
bashnpm install zustand
These are entry points of the same package, not separate packages to install. Follow each reference link for its exports, types, and signatures.
| Entry point | What it provides |
|---|---|
zustand | The core store API and React bindings together. |
zustand/vanilla | Standalone stores with imperative reads, updates, and subscriptions, without importing React. |
zustand/react | React hooks for creating bound stores and subscribing to vanilla stores. |
zustand/middleware | Middleware for persistence, Redux DevTools, reducer-based actions, inferred state, and selector subscriptions. |
zustand/react/shallow | A React selector helper that retains a previous result when the new result is shallowly equal. |
zustand/vanilla/shallow | Shallow comparison without importing React. |
zustand/shallow | Both the shallow comparator and the React selector helper. |
zustand/traditional | React bindings that accept custom equality functions; these use the additional use-sync-external-store package. |
zustand/middleware/immer | Draft-based state updates using the additional immer package. |
The guides for custom equality and Immer include the additional installation commands for those integrations.
Start with React
Take the React quick start to install Zustand and build a typed counter with an action and component selectors. If you need a store outside React, read Stores and React bindings to distinguish the standalone store from its React hook.
Find your task
Concepts
How Zustand works connects independent stores, immutable updates, selector subscriptions, and actions; continue with Stores and React bindings, Immutable state and merging, and Selectors and rendering for the details that shape your code.
Guides
- Editing state: Update and reset state, work with Maps and Sets or Immer drafts, and organize actions; the tic-tac-toe tutorial puts shared state and time travel into a playable interface.
- Structuring stores: Type stores and selectors, then split a growing store into slices while keeping a combined store.
- Subscribing and rendering: Select computed state and customize equality checks and subscriptions to control which changes your components and imperative listeners observe.
- Saving and restoring: Persist store state, control hydration, migrate saved data, or synchronize state with the URL.
- Scoping and server rendering: Scope stores with context for isolated component trees and server-render React stores with per-request ownership and matching initial state.
- Debugging and maintenance: Inspect actions with Redux DevTools, test stores and components, and migrate existing stores to v5.
- Extending: Implement custom storage or write typed middleware when the shipped integrations do not meet your requirements.
API reference
Use the entry-point references above when you need an exact signature, type, or option rather than a task walkthrough: start with the core package for stores and React hooks, or middleware for composable store behavior.
Was this page helpful?