Training Grounds
Counter Freezes at 1White Belt
+10 Ki
Description

A live ticker displays a number that should increment every second automatically from the moment the component mounts.

Anomaly

The ticker reaches 1 after the first second and then freezes. It never increments past 1 no matter how long you wait.

Constraint
Do not remove the setInterval
Do not change the interval duration
Hint

The callback passed to setInterval captures variables at the time it is created - what value does it always see?

Consult the SenseiOnly for those truly stuck · Flip to reveal

The callback passed to setInterval captures variables at the time it is created - what value does it always see?

Practice 41 related drills →
Loading editor…
Correct Solution
Loading...

Why this fixes it

The interval callback closed over `count` at mount, permanently capturing `0`. Every tick called `setCount(0 + 1)` which is always `1`. After the first tick count was already `1`, so React's equality check bailed out - the counter froze. Replacing with `setCount((c) => c + 1)` uses a functional updater that receives the actual current state from React's queue on each tick, so each call correctly increments from the real current value.

Expected OutputGoal State
Your OutputLive