The CartProvider component creates a context for using a cart. It creates a cart object and callbacks that can be accessed by any descendent component using the useCart hook and related hooks. It also carries out any callback props when a relevant action is performed. For example, if a onLineAdd callback is provided, then the callback will be 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 if you want to use the useCart hook or related hooks, or if you would like to use the AddToCartButton component.