Training Grounds
Doubled Counter Frozen at ZeroBlue Belt
+25 Ki
Description

A counter displays its value and a doubled version that updates in sync with every increment.

Anomaly

Click Increment - Count goes up correctly but Doubled stays at 0 forever.

Constraint
adding count to the useEffect dependency array is not a valid fix - it introduces a one-render lag that Test 3 will catch
Hint

Ask yourself whether `doubled` really needs to be state at all.

Consult the SenseiOnly for those truly stuck · Flip to reveal

Ask yourself whether `doubled` really needs to be state at all.

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

Why this fixes it

`doubled` was stored as a separate `useState` and synced via a `useEffect` with an empty dependency array - the effect ran once on mount and never again, leaving `doubled` frozen at `0`. Removing both and computing `const doubled = count * 2` inline during render means the value is recalculated on every render from the current `count` with no synchronization lag.

Expected OutputGoal State
Your OutputLive