Command Palette

Search for a command to run...

Hectal
Phase 10: Custom Hooks and Reusable Logic
React · Exercise 2 of 6 PreviousNext
Beginner

One hook, two independent counters

Write useCounter(initial, step) that returns { count, increment, reset }. increment adds step; reset goes back to initial.

Use it twice in Scoreboard: apples start at 0 and go up by 1 (button id="apples", text Apples: N); score starts at 10 and goes up by 5 (button id="score", text Score: N). A button id="reset-score" resets only the score.

What Check tests

  1. It starts at Apples: 0 and Score: 10
  2. Two apple clicks show Apples: 2 and leave the score alone
  3. A score click adds 5
  4. Reset score goes back to 10 and keeps the apples
  5. Both counters come from useCounter

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.