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
MuhammedAlaaOP•2y ago
okay np i was spelling it wrong in the props of the cartside bar 😄
k-2
k-2•2y ago
hi guys, please whats wrong with my code? why the button is not within the parent container
k-2
k-2•2y ago
vince
vince•2y ago
Make a new thread
Want results from more Discord servers?
Add your server