notrab / react-use-cart

React hook library for managing cart state

Home Page:http://npm.im/react-use-cart

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

'totalCart' is always 0 when use multiple carts

nachoaldamav opened this issue · comments

I'm trying to add multiple carts to my website, one per "pack", the problem is that i can't use cartTotal.

/pages/pack/[id].js

import { CartProvider,} from "react-use-cart";
import CartComponent from "../../components/CartComponent";

export default function PackPage({ data }) {
return (
   <CartProvider id={data.seller.id}>
      ... Render the page component
      <CartComponent />
   </CartProvider>
  )
}

/components/CartComponent/

import { useCart } from "react-use-cart";

export default function CartComponent() {
  const { cartTotal } = useCart();
  return (
    <div>
      <h4>{cartTotal}</h4> // This is always 0
    </div>
  );
}

Somehow it works now! sorry for the issue! 😂

PS: If you have this error try moving the cartTotal to another component!