Training Grounds
Array Push Freezes the ListWhite Belt
+10 Ki
Description

A task list lets the user type a task name and add it to an accumulating list by clicking a button.

Anomaly

Type any task name, click Add - the input clears but the list stays empty every single time. No tasks ever accumulate.

Constraint
Do not replace useState with useReducer
Hint

Look closely at what `setTasks` is being called with.

Consult the SenseiOnly for those truly stuck · Flip to reveal

Look closely at what `setTasks` is being called with.

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

Why this fixes it

`tasks.push(input)` mutated the existing array then `setTasks([])` discarded it entirely, resetting the list to empty on every add. Replacing both lines with `setTasks([...tasks, input])` creates a new array containing all previous items plus the new one, which React detects as a state change and re-renders with the accumulated list.

Expected OutputGoal State
Your OutputLive