Training Grounds
Counter Spins Up and Never StopsWhite Belt
+10 Ki
Description

A counter starts at zero and increments once on mount, settling at 1.

Anomaly

The counter rockets upward continuously and never settles.

Constraint
The fetch must stay inside the useEffect
Do not add a loading guard or extra state
Hint

Think about what's in the dependency array and what happens after the effect runs.

Consult the SenseiOnly for those truly stuck · Flip to reveal

Think about what's in the dependency array and what happens after the effect runs.

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

Why this fixes it

The effect read `count` from its closure and called `setCount(next)`, which updated `count`, which was listed as a dependency, which caused the effect to re-run - a render loop with no exit. Changing the dependency array to `[]` and using `setCount(prev => prev + 1)` breaks the cycle: the effect runs only once on mount and the functional updater removes the need to close over `count` at all.

Expected OutputGoal State
Your OutputLive