I am trying to remove the specific product a user is clicking on.
So far, when you are trying to remove a product from the cart it removes based on the ID the product has. Though, I need it to check size, color, and ID. I don't want it to remove both "Product A, size M" and "Product A, size L" if the user is only clicking on size M.
If I try to remove the "size M" one, it should only
remove the "size M" one, not the "size L" as well (as both of them have the same ID).
Here is my code where the deletion of a product is:
const removeItemHandler = (e) => {
let id = e.currentTarget.getAttribute("itemid");
let size = e.currentTarget.getAttribute("size");
let color = e.currentTarget.getAttribute("color");
const clonedCartItems = JSON.parse(JSON.stringify(cartItems));
// Here is where I am trying to filter out the product. So it will only take the one the user is
clicking on
let newCart = clonedCartItems.filter(
(elem) => elem.id !== id && elem.size !== size
);
setCartItems(newCart);
};
Thanks!