Skip to content

Zustand

A small React state-management library built on hooks, with no providers needed.

Stars
58.9k
Forks
2.2k
Licence
MIT
Language
TypeScript
Last update
15 days ago
Type
Library

What it is

Zustand lets React apps keep shared state in a store that components read through a hook. Components subscribe to just the pieces they select and re-render only when those pieces change. The README says it needs no context providers and has a small API, and it can also be used without React.

  • Create a counter store with actions and read it in separate components with a selector hook
  • Select several state values at once with useShallow to avoid unnecessary re-renders
  • Subscribe to specific store changes outside React using subscribe with the subscribeWithSelector middleware
  • Use the core store without React via the zustand/vanilla entry point

Great for

  • React developers who want simpler shared state than Redux
  • Apps that need state shared across many components without wrapping them in providers
  • Projects that need to read or update state outside components via getState and setState
  • Developers who want fine control over which state changes trigger re-renders

Not ideal for

  • Teams that require Redux's conventions, tooling, and strict structure, since the README describes zustand as un-opinionated
  • Projects not using React or JavaScript, since the README focuses on JavaScript and React usage and the vanilla core is only a secondary option
  • Adding state inside React Server Components, which the README explicitly advises against because it can cause bugs and privacy issues
Step-by-step guide: how to use ZustandInstall, first run, examples, tips and FAQs

How to get it

  1. 1

    Install with a package manager

    You'll need: Node.js and npm

    Install zustand from npm

    npm install zustand
  2. 2

    Run it

    • Install the package with npm install zustand
    • Create a store with create((set) => ({ ... })) and define state and actions
    • Call the store hook in a component, passing a selector to pick the state you need
    • Update state by calling set from an action
  3. 3

    Get the most out of it

    • Use useShallow when a selector returns an object or array to avoid unnecessary re-renders
    • Use the subscribeWithSelector middleware to react to specific state changes outside components
    • Use getState and setState for non-reactive reads and writes when needed
    • Read the TypeScript Usage section and the docs site for typing details

Downloads

Strengths

  • Small, simple API based on hooks, with no providers required
  • Components re-render only when the selected state they read changes
  • Works with async actions and can be used outside React

Trade-offs

  • The README says to set state immutably and be careful when replacing state, which takes care to get right
  • Some patterns, such as fetching everything or using custom equality, can cause extra re-renders or require extra setup
  • Documentation for the migration to v5 and TypeScript usage is referenced but not included in the truncated README

How it compares

ProjectStarsTypeLevelUpdatedBest for
zustand (this)58.9kLibrarybeginner15 days agoReact developers who want simpler shared state than Redux
redux61.4kLibraryintermediate16 days agoDevelopers building larger front-end apps where many components share the same data
jotai21.3kLibrarybeginner14 days agoReact developers who want simple shared state without heavy setup
Recoil19.4kLibraryintermediate1.8 years agoReact developers who want shared state beyond simple prop passing
valtio10.2kLibraryintermediate7 days agoReact developers who want simple shared state without a lot of boilerplate
table28.5kLibraryintermediate15 days agoDevelopers building custom data tables in React, Vue, Solid, Svelte or another supported framework

Stats synced from GitHub. The assessment above was drafted with AI from the project's README on 2026-10-29 and may miss recent changes — check the README before relying on a command. MIT licence: free to use, modify and distribute, including commercially, as long as you keep the copyright notice.