Increase the product quantity in the cart

this is the function
const handleCart = (product, redirect) => {
const isProductExist = cartItems.find(
(item) => item.id === product.id && item.size === selectedSize
);
if (isProductExist) {
const updatedCart = cartItems.map((item) => {
if (item.id === product.id && item.size === selectedSize) {
return {
...item,
quantity: item.quantity + 1,
};
}
return item;
});
setCartItems(updatedCart);
} else {
setCartItems([
...cartItems,
{ ...product, quantity: 1, size: selectedSize },
]);
}
if (redirect) {
navigate("/cart");
}
};
const handleCart = (product, redirect) => {
const isProductExist = cartItems.find(
(item) => item.id === product.id && item.size === selectedSize
);
if (isProductExist) {
const updatedCart = cartItems.map((item) => {
if (item.id === product.id && item.size === selectedSize) {
return {
...item,
quantity: item.quantity + 1,
};
}
return item;
});
setCartItems(updatedCart);
} else {
setCartItems([
...cartItems,
{ ...product, quantity: 1, size: selectedSize },
]);
}
if (redirect) {
navigate("/cart");
}
};
i passes it to the navbar component then from the nav i pass it to the cartsidebar like that
<Nav
addClass={true}
totalItems={totalQuantity}
handleCart={handleCart}
/>
<Nav
addClass={true}
totalItems={totalQuantity}
handleCart={handleCart}
/>
{isCartOpen && (
<CartSideBar
isCartOpen={isCartOpen}
setisCartOpen={setIsCartOpen}
handleCart={handleCart}
/>
)}
{isCartOpen && (
<CartSideBar
isCartOpen={isCartOpen}
setisCartOpen={setIsCartOpen}
handleCart={handleCart}
/>
)}
this is the button
<button
className="p-0 bg-transparent"
onClick={() => handelCart(cartItems[i])}
>
<button
className="p-0 bg-transparent"
onClick={() => handelCart(cartItems[i])}
>
why it says handleCart is not a function
4 Replies
MuhammedAlaa
MuhammedAlaa•12mo ago
okay np i was spelling it wrong in the props of the cartside bar 😄
k-2
k-2•12mo ago
hi guys, please whats wrong with my code? why the button is not within the parent container
k-2
k-2•12mo ago
vince
vince•12mo ago
Make a new thread