I am currently working on a React-Redux based Cart app, and I am experiencing the following problem:
When I continuously click the remove button in order to remove a product from my cart, the quantity goes below zero. Any solutions on how to end the quantity at 1 and then remove the the whole product from the front end when there is one left?
Below is my function:
case 'REMOVE_FROM_CART':
return {
...state,
cart: state.cart.filter(item => item.id !== action.payload.id),
cart: state.cart.map(item =>
item.id === action.payload.id
? { ...item, quantity: item.quantity - 1 }
: item
),
};
