in this code, instead of showing "The product has been added to cart." alert message, I want to update cart quantity if item already exist in cart, please help me out.
const addToCart = (id) => {
const check = cart.every((item) => {
return item.id !== id;
});
if (check) {
const cartData = products.filter((el) => {
return el.id === id;
});
setCart([...cart, ...cartData]);
} else {
alert('The product has been added to cart.');
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…