Command Palette

Search for a command to run...

Hectal
Phase 15: State Management at Scale
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

  1. The count starts at 0
  2. Clicking #inc twice shows 2
  3. Clicking #reset shows 0 again
  4. 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.