zustand
Zustand is a small, fast, and scalable state management library for React that provides a simple hook-based API without boilerplate. The name means 'state' in G…
Installation
npm install zustand
yarn add zustand
pnpm add zustand
Import
import { create } from 'zustand';Quick Example
import { create } from 'zustand';
const useStore = create((set) => ({
count: 0,
increment: () => set((s) => ({ count: s.count + 1 })),
decrement: () => set((s) => ({ count: s.count - 1 })),
}));
function Counter() {
const count = useStore((s) => s.count);
const increment = useStore((s) => s.increment);
return <button onClick={increment}>{count}</button>;
}About zustand
Zustand is a small, fast, and scalable state management library for React that provides a simple hook-based API without boilerplate. The name means 'state' in German. Zustand creates stores using a create function that accepts a callback defining the state shape and actions: create((set) => ({ count: 0, increment: () => set(state => ({ count: state.count + 1 })) })). Components access state through the returned hook with automatic re-rendering only when selected state changes: const count = useStore(state => state.count). This selector-based approach provides fine-grained reactivity without context providers, reducing unnecessary re-renders. Zustand supports middleware for persistence (localStorage, sessionStorage), devtools integration, Immer for immutable updates, and computed/derived state. The library works outside React as a vanilla store, enabling shared state between React and non-React code. Zustand handles async actions naturally since actions are just functions that call set(). The subscribe API enables reacting to state changes outside components. Zustand has become the most popular alternative to Redux for React state management, appreciated for its minimal API surface, excellent TypeScript support, and ability to handle both simple and complex state management needs without ceremony.
Quick Facts
| Package | zustand |
| Category | State Management |
| Weekly Downloads | 5M+ |
| License | MIT |
| Install | npm install zustand |
Related Packages
Redux is a predictable state container for JavaScript applications, most commonly used with React bu…
Jotai is a primitive and flexible state management library for React that takes an atomic approach i…
Valtio is a proxy-based state management library for React that makes state management as simple as …
MobX is a battle-tested state management library that makes state management simple and scalable thr…
React is the most popular JavaScript library for building user interfaces, developed and maintained …
Browse npm Packages by Category
Explore our reference of 200 popular npm packages with install commands, examples, and quick-start guides.