The CartProvider component creates a context for using a cart. It creates a cart object and callbacks that any descendent component can access using the useCart hook and related hooks. CartProvider also carries out any callback props when a relevant action is performed. For example, if an onLineAdd callback is provided, then the callback is called when a new line item is successfully added to the cart.

The CartProvider component must be a descendent of the ShopifyProvider component.

You must use this component to use the following:

  • The useCart hook or related hooks

  • The AddToCartButton component