Training Grounds
Counter Never UpdatesWhite Belt
+10 Ki
Description

A counter displays a number and a button increments it. The counter never changes when clicked.

Anomaly

Clicking the button does nothing — the number stays at 0 no matter how many times you click.

Constraint
Do not add useEffect or any other hook
Hint

Check what value you're actually passing to setCount

Consult the SenseiOnly for those truly stuck · Flip to reveal

Check what value you're actually passing to setCount

Loading editor…
Correct Solution
Loading...

Why this fixes it

setCount(count) passed the current value of count straight back into state - because React uses Object.is equality, it compared the new value against the old one, saw they were identical, and bailed out of the re-render entirely. Changing the argument to count + 1 produces a value that is always different from the current state. React detects the new value, schedules a re-render, and the updated count appears on screen.

Expected OutputGoal State
Your OutputLive