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");
    }
  };

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}
      />

{isCartOpen && (
          <CartSideBar
            isCartOpen={isCartOpen}
            setisCartOpen={setIsCartOpen}
            handleCart={handleCart}
          />
        )}


this is the button
<button
                                className="p-0 bg-transparent"
                                onClick={() => handelCart(cartItems[i])}
                              >


why it says handleCart is not a function
image.png
image.png
Was this page helpful?