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] to compute the discount — but state is the state from before this action ran, so it always looked up the previously applied code, not the one dispatched. On the first click from a clean state, state.code was an empty string so the lookup returned undefined and discount stayed 0%. The fix changes state.code to action.code, which is the code that was just dispatched. The reducer now computes the correct discount immediately from the current action.