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.
- Redux A JS library for predictable global state management
- Jotai Atomic state management for React
- redux-persist Saves a Redux store to storage as it changes and restores it when the app starts
- Valtio Proxy-based state for React and vanilla JavaScript
- dva Lightweight Elm-style React framework built on Redux, redux-saga and react-router
