talira

Bear necessities for React state

open sourceMITfree

Zustand is a small state-management library for React from Poimandres. A store is a hook: you create it with one call, put state and the functions that change it inside, and components select the slices they need and re-render when those change, with no providers or boilerplate. It's built to avoid React's zombie-child and tearing problems under concurrency, and the same store works outside React. Middleware adds devtools, persistence, Redux-style reducers and Immer.

Problems it solves

  • share state between React components without prop drilling or a context provider
  • Redux feels like too much boilerplate for my React app
  • keep global state in a React Native app
  • persist part of my React app's state to localStorage

Features

  • stores as hooks, no providers
  • selectors that re-render only on change
  • works with React, React Native and vanilla JavaScript
  • middleware for devtools, persistence, Redux-style reducers and Immer
  • TypeScript types

Alternatives

The same job

These do what Zustand does.

  1. Redux A JS library for predictable global state management
  2. Jotai Atomic state management for React
  3. redux-persist Saves a Redux store to storage as it changes and restores it when the app starts
  4. Valtio Proxy-based state for React and vanilla JavaScript
  5. dva Lightweight Elm-style React framework built on Redux, redux-saga and react-router

Compare Zustand with the top 3