Zustand — Bear-Sized State Management for React
Zustand is a small, fast, and scalable bearbones state-management solution for React. A cozy alternative to Redux with a simple hooks API, no providers needed, and first-class TypeScript support.
What it is
Zustand is a lightweight state management library for React. It uses a simple hooks-based API, requires no context providers, and supports TypeScript out of the box. At under 1KB gzipped, it is one of the smallest state management solutions available.
Zustand targets React developers who want global state without the boilerplate of Redux or the complexity of context-based solutions.
How it saves time or tokens
Zustand eliminates provider wrappers, action creators, reducers, and dispatch patterns. You define a store in one function call and consume it with a hook. No selectors library, no middleware setup, no normalized state shape required.
How to use
- Install Zustand:
npm i zustand
- Create a store:
import { create } from 'zustand';
type BearStore = {
bears: number;
increase: () => void;
reset: () => void;
};
export const useBearStore = create<BearStore>((set) => ({
bears: 0,
increase: () => set((s) => ({ bears: s.bears + 1 })),
reset: () => set({ bears: 0 }),
}));
- Use in any component — no provider needed:
function Counter() {
const bears = useBearStore((s) => s.bears);
const increase = useBearStore((s) => s.increase);
return <button onClick={increase}>{bears} bears</button>;
}
Example
import { create } from 'zustand';
interface TodoStore {
todos: string[];
add: (todo: string) => void;
clear: () => void;
}
const useTodoStore = create<TodoStore>((set) => ({
todos: [],
add: (todo) => set((s) => ({ todos: [...s.todos, todo] })),
clear: () => set({ todos: [] }),
}));
// Use anywhere without wrapping in a Provider
function TodoList() {
const todos = useTodoStore((s) => s.todos);
return <ul>{todos.map((t) => <li key={t}>{t}</li>)}</ul>;
}
Related on TokRepo
- AI Tools for Coding — Frontend development tools and libraries
- Featured Workflows — Discover trending React tools
Key considerations
When evaluating Zustand for your workflow, consider the following factors. First, assess whether your team has the technical prerequisites to adopt this tool effectively. Second, evaluate the maintenance burden against the productivity gains. Third, check community activity and documentation quality to ensure long-term viability. Integration with your existing toolchain matters more than feature count alone. Start with a small pilot project before rolling out across the organization. Monitor resource usage during the initial adoption phase to identify bottlenecks early. Document your configuration decisions so team members can onboard independently.
Common pitfalls
- Selecting the entire store object (no selector function) causes unnecessary re-renders; always use selector functions.
- Zustand stores are singletons; in SSR frameworks like Next.js, use per-request store creation to avoid data leaking between users.
- Middleware (persist, devtools) must be applied at store creation time; they cannot be added later.
Frequently Asked Questions
Zustand is much simpler. No action types, reducers, or dispatch. You define state and actions in one function. Redux offers more structure and middleware ecosystem for large applications. Zustand is better for small to medium state needs.
Yes. Zustand works with Next.js, but SSR requires care. Create stores per-request to avoid sharing state between users. The Zustand documentation covers Next.js patterns specifically.
Yes. Zustand has first-class TypeScript support. Define your store type and Zustand infers selector return types, action parameters, and state shape automatically.
Yes. Zustand's persist middleware saves state to localStorage, sessionStorage, or any custom storage adapter. State is automatically rehydrated when the app loads.
Zustand is under 1KB gzipped. It has no dependencies beyond React. This makes it one of the smallest state management libraries available for React.
Citations (3)
- Zustand GitHub— Small, fast state management for React with hooks API
- Zustand Demo— No providers needed, under 1KB gzipped
- Zustand Documentation— First-class TypeScript support and persist middleware
Related on TokRepo
Discussion
Related Assets
Hugging Face Datasets — Access and Process ML Datasets at Scale
Hugging Face Datasets is a Python library for efficiently loading, processing, and sharing machine learning datasets with Apache Arrow-backed memory mapping, streaming support, and access to thousands of community datasets on the Hub.
OpenVoice — Instant Voice Cloning with Tone and Style Control
OpenVoice is an open-source voice cloning framework from MyShell AI that reproduces a speaker's voice from a short audio sample while giving independent control over emotion, accent, rhythm, and language.
Segment Anything (SAM) — Foundation Model for Image Segmentation
Segment Anything Model by Meta AI provides a promptable segmentation system that can isolate any object in an image given points, boxes, or text prompts, enabling zero-shot transfer to new visual domains.