Hello everyone, I am making a simple shop website where you can add to cart and remove from it.
The add to cart function is working, however my remove function is not.
addToCart({ title, desc, price, image }) {
this.setState({
cart: [
...this.state.cart,
{
title,
desc,
price,
image,
},
],
total: this.state.total + price
});
}
// the item id and price
Removefromcart({ title, desc, price, image, id }) {
this.setState(state => ({
cart: this.state.cart.filter(item => item.id !== id),
total: state.total - price
}));
}
When the function fires nothing happens. No error message or anything, that’s what’s making it so hard for me to see what’s going on.
I have a feeling I am just making a stupid mistake, so I am just asking for another pair of eyes to see what I can’t.
The full code is here: https://codesandbox.io/s/vigilant-dubinsky-0d57h
Thank you for your time.