React · Exercise 1 of 5Next
Intermediate
Your first Zustand store
Turn this counter into a Zustand store. Create useCounter with create from zustand, holding count (starting at 0) and two actions: inc (adds 1) and reset (back to 0).
Display shows the count in the element with id="count". Controls has a button id="inc" and a button id="reset" that call the actions. Read each value with a selector (useCounter((s) => s.count)).
What Check tests
- The count starts at 0
- Clicking
#inctwice shows 2 - Clicking
#resetshows 0 again - The actions live in the store and are read with selectors
Stuck? One hint at a time
The solution unlocks after your first Check. Try first: that is where the learning happens.
Runs in your browser. Your code is saved here.
Your page
Press Run to see the page.
Console
Nothing logged yet.