📈 GH Trending Explorer 🎲 Surprise me

← all repos

pmndrs / zustand

git clone https://github.com/pmndrs/zustand.git v5.0.16 · 1d ago

🐻 Bear necessities for state management in React

+12
stars, 24h · #2,988
+~37
stars, 7 days · #5,247
+~160
stars, 30 days · #4,838
59k
★ total · +0% this week
2.2k
forks · 4 open issues

Star history (as recorded here)

2026-10-20 · 58,845 ★ 2026-10-23 · 58,861 ★
LanguageTypeScript
LicenseMIT
Created2019-04-09 (7y ago)
Last push1d ago
Watchers196
OwnerOrganization

GitHub topics

Links

README excerpt
A small, fast and scalable bearbones state-management solution using simplified flux principles. Has a comfy API based on hooks, isn't boilerplatey or opinionated.
Don't disregard it because it's cute. It has quite the claws, lots of time was spent dealing with common pitfalls, like the dreaded zombie child problem, react concurrency, and context loss between mixed renderers. It may be the one state-manager in the React space that gets all of these right.
You can try a live demo and read the docs.
 [code] 
:warning: This readme is written for JavaScript users. If you are a TypeScript user, be sure to check out our TypeScript Usage section.
## First create a store
Your store is a hook! You can put anything in it: primitives, objects, functions. State has to be updated immutably and the `set` function merges state to help it.
 [code] 
## Then bind your components, and that's it!
Use the hook anywhere, no providers are needed. Select your state and the component will re-render on changes.
 [code] 
### Why zustand over redux?
- Simple and un-opinionated
- Makes hooks the primary means of consuming state
- Doesn't wrap your app in context providers
- Can inform components transiently (without causing render)
### Why zustand over context?
- Less boilerplate
- Renders components only on changes
- Centralized, action-based state management
---
# Recipes
## Fetching everything
You can, but bear in mind that it will cause the component to update on every state change!
 [code] 
## Selecting multiple state slices
It detects changes with strict-equality (old === new) by default, this is efficient for atomic state picks.
 [code] 
If you want to construct a single object with multiple state-picks inside, similar to redux's mapStateToProps, you can use useShallow to prevent unnecessary rerenders when the selector output does not change according to shallow equal.
 [code] 
For more control over re-rendering, you may provide any custom equality function (this example requires the use of `createWithEqualityFn`).
 [code] 
## Overwriting state
The `set` function has a second argument, `false` by default. Instead of merging, it will replace the state model. Be careful not to wipe out parts you rely on, like actions.
 [code] 
## Async actions
Just call `set` when you're ready, zustand doesn't care if your actions are async or not.
 [code] 
## Read from state in actions
`set` allows fn-updates `set(state => result)`, but you still have access to state outside of it through `get`.
 [code] 
## Reading/writing state and reacting to changes outside of components
Sometimes you need to access state in a non-reactive way or act upon the store. For these cases, the resulting hook has utility functions attached to its prototype.
:warning: This technique is not recommended for adding state in React Server Components (typically in Next.js 13 and above). It can lead to unexpected bugs and privacy issues for your users. For more details, see #2200.
 [code] 
### Using subscribe with