0
Challenge · 63Architecture & State
Zustand
Ecoused in ~45% of apps
You need to share state across the app, but Context makes every consumer re-render and Redux Toolkit is a lot of ceremony for a theme toggle or a cart. Zustand is a single store you read with a hook and a selector — no Provider, no boilerplate, and only the components that select a changed slice re-render.
Core idea. create((set) => ({ ...state, ...actions })) returns a hook; components call useStore(s => s.slice) to subscribe to exactly the slice they read, and call an action to set() new state — re-renders are scoped to the selected slice, with no Provider in the tree.
poke it, drag it,
try to break it
try to break it
no slides here.
you drive.
you drive.
Playground, this isn't a screenshot
const useStore = create((set) => (...))no Provider
count#1
0
text#1
"hi"
three separate components — each calls useStore(selector)
1×
<Count />
useStore(s => s.count)
1×
<Label />
useStore(s => s.text)
1×
<Whole />
useStore(s => s (no slice))
One store, no Provider. Press a button: only components whose selector picks that slice re-render.
re-rendered (red flash) render count
↑ play a little first, then dig in