Training Grounds
useReducer Wrong Action TypeBlack Belt
+50 Ki
Description

A like button shows a count and toggles between liked and unliked. Clicking Like adds 1 to the count. Clicking Unlike should remove 1 — instead the count keeps going up.

Anomaly

Click Like — count goes to 1, button shows Unlike. Click Unlike — count goes to 2 instead of back to 0. Every click increments regardless of direction.

Constraint
Fix only the dispatch call in the onClick handler
Do not change the reducer logic
Hint

The reducer handles the UNLIKE action, but the button dispatches the wrong action type — it dispatches LIKE on both clicks.

Consult the SenseiOnly for those truly stuck · Flip to reveal

The reducer handles the UNLIKE action, but the button dispatches the wrong action type — it dispatches LIKE on both clicks.

Loading editor…
Correct Solution
Loading...
Expected OutputGoal State
Your OutputLive