API Reference

Zustand

Small state management library for React with a hook-based store, selectors and no boilerplate.

Official Documentation ↗
CompatibilityThis documentation covers version v5.0.16. Check the official docs for the latest API surface.

Installation

npmnpm install zustand
pnpmpnpm add zustand
yarnyarn add zustand

Methods

Overview

Zustand manages React state through a store hook that lives outside the component tree. There is no provider requirement and no boilerplate, and components subscribe to the slices they use.

Core Methods

create builds a store with state and actions. set merges updates, get reads state, and the returned hook plus store.subscribe expose reactive reads both inside and outside React.

Usage Notes

Split stores by concern, select minimal slices, and keep actions close to the state they change. Use middleware for persistence, devtools and immutability helpers.

Common Pitfalls

Selecting whole objects re-renders components on unrelated changes. Mutating state in place breaks change detection, so always create new objects. Stores are module singletons, so per-request state in SSR must be handled carefully.

Security notes

Quoted verbatim from the official documentation; this is not a complete threat model. 来源:https://cdn.jsdelivr.net/gh/pmndrs/zustand@latest/README.md · 取证方式:HTTP GET 官方 README/文档页(HTML 去标签) · 抓取时间:2026-11-07T13:53:35.352Z.

FAQ

What makes Zustand different from Redux?
Zustand stores are plain hooks without actions, reducers or providers. State lives outside React and components select the slices they need, which reduces boilerplate and re-renders.
How do I avoid unnecessary re-renders?
Use selectors that return primitive values or stable references, or a shallow equality function. Selecting whole objects causes re-renders when any field changes.
Can state persist?
A persist middleware saves the store to storage such as localStorage or a custom storage adapter. Choose which keys to persist and handle rehydration to avoid stale data.