Problem
Once an item is added to the basket, there is no way to remove it from
the Checkout page. CheckoutProduct.js renders each item but has no
remove button. The REMOVE_FROM_BASKET action type is either missing
from reducer.js or exists but is never dispatched from the UI.
Steps to Reproduce
- Add any item to basket via "Add to Basket" button
- Navigate to
/checkout
- Observe: no remove/delete button on any basket item
- The only way to empty the basket is to complete a payment
Expected Behaviour
Each item in the checkout should have a "Remove from Basket" button.
Fix — reducer.js
case 'REMOVE_FROM_BASKET': {
const index = state.basket.findIndex(item => item.id === action.id);
let newBasket = [...state.basket];
if (index >= 0) {
newBasket.splice(index, 1);
} else {
console.warn(`Item ${action.id} not found in basket`);
}
return { ...state, basket: newBasket };
}
Fix — CheckoutProduct.js
const [{ basket }, dispatch] = useStateValue();
const removeFromBasket = () => {
dispatch({
type: 'REMOVE_FROM_BASKET',
id: id,
});
};
// Add to JSX:
<button onClick={removeFromBasket} className="checkout-product__remove">
Remove from Basket
</button>
Why this matters
Without this, users who accidentally add the wrong item — or add
duplicates — have no recourse short of completing a payment to trigger
EMPTY_BASKET.
Problem
Once an item is added to the basket, there is no way to remove it from
the Checkout page.
CheckoutProduct.jsrenders each item but has noremove button. The
REMOVE_FROM_BASKETaction type is either missingfrom
reducer.jsor exists but is never dispatched from the UI.Steps to Reproduce
/checkoutExpected Behaviour
Each item in the checkout should have a "Remove from Basket" button.
Fix — reducer.js
Fix — CheckoutProduct.js
Why this matters
Without this, users who accidentally add the wrong item — or add
duplicates — have no recourse short of completing a payment to trigger
EMPTY_BASKET.