I am trying to have items be addable (done) however I am having an issue with trying to remove an item from the users cart.
Removefromcart = (cart, id) => {
// using an updater function
this.setState(({
// keep everything except the item with the id that was passed in
cart: this.state.cart.filter(cart => cart.id !== id),
// item price - current state total
// total: state.total - price
}));
};
As you can see I am trying to use a filter to remove everything except the id of what was clicked. However right now it seems to be erasing the array completely. Before that it wasn't affecting the array at all. In case it is relevant here is a link to my full code: https://codesandbox.io/s/vigilant-dubinsky-0d57h