Cart with a Reducer
Write the code, see it run, pass the checks.
The problem
- hard
- Code
- Pro
Build a cart for three products: Tea (£3), Cake (£4) and Jam (£5). Each has an "Add Tea" and a "Remove Tea" button (and the same for Cake and Jam). List only the products in the cart with their quantity, like "Tea × 2", and show the total as "Total: £11". Remove never takes a quantity below zero. Tip: a reducer (useReducer) keeps the add and remove rules in one place.
Your code must pass
- Adding products updates the total
- Only products in the cart are listed, with quantities
- Remove takes one away
- Removing below zero does nothing