A checkout panel has three preset discount buttons. Clicking a button should apply that discount immediately and update the total.
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.
Inside the reducer, the new value arrives in one place and the current value lives in another - which one are you reading?
Inside the reducer, the new value arrives in one place and the current value lives in another - which one are you reading?
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.