📦
State Management5M+/wkMIT

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
npm install zustand
yarn
yarn add zustand
pnpm
pnpm add zustand

Import

ESM
import { create } from 'zustand';

Quick Example

usage
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

Packagezustand
CategoryState Management
Weekly Downloads5M+
LicenseMIT
Installnpm install zustand

Related Packages

Browse npm Packages by Category

Explore our reference of 200 popular npm packages with install commands, examples, and quick-start guides.