Command Palette

Search for a command to run...

Hectal
Phase 0: Start Here: Why React
React · Exercise 3 of 5 PreviousNext
Beginner

Fix the counter that never changes

This counter uses a normal variable, so clicking does nothing on screen. Make it work: the button (it has id="add") must show Clicks: 0 at the start and go up by one on every click.

Use useState from React to give the component memory.

What Check tests

  1. The button starts at Clicks: 0
  2. One click shows Clicks: 1
  3. Two more clicks show Clicks: 3
  4. The component uses useState

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.