Description

A checkout panel has three preset discount buttons. Clicking a button should apply that discount immediately and update the total.

Anomaly

Click any discount button - the Discount line stays at 0% and Total stays at $100. The code label updates to show the button you clicked but the numbers never change. Click the same button a second time and the discount from the first click finally appears.

Constraint
Do not replace useReducer with useState
Do not change the dispatch calls or the button layout
Hint
Consult the SenseiOnly for those truly stuck · Flip to reveal

Inside the reducer, the new value arrives in one place and the current value lives in another - which one are you reading?

Loading editor…
Correct Solution
Loading...

Why this fixes it

The reducer read `CODES[state.code]` - but `state` is the state before this action, so it always computed the discount for the previously applied code. On the first click from a clean state `state.code` was empty so discount was 0%. Changing to `CODES[action.code]` computes the discount from the code just dispatched, so the result is correct immediately on the first click.

Expected OutputGoal State
Your OutputLive