Cart Provider
The CartProvider component synchronizes the state of the Storefront API Cart and a customer's cart, and allows you to more easily manipulate the cart by adding, removing, and updating it. It could be placed at the root of your app so that your whole app is able to use the useCart() hook anywhere.
There are props that trigger when a call to the Storefront API is made, such as onLineAdd={} when a line is added to the cart. There are also props that trigger when a call to the Storefront API is completed, such as onLineAddComplete={} when the fetch request for adding a line to the cart completes.
The CartProvider component must be a descendant of the ShopifyProvider component
.
Anchor to propsProps
- Anchor to childrenchildrenchildrenReact.ReactNodeReact.ReactNoderequiredrequired
Any
elements.- Anchor to cartFragmentcart
Fragmentcart Fragment stringstring A fragment used to query the Storefront API's Cart object for all queries and mutations. A default value is used if no argument is provided.
- Anchor to countryCodecountry
Codecountry Code CountryCodeCountryCode The ISO country code for i18n.
- Anchor to customerAccessTokencustomer
Access Tokencustomer Access Token stringstring A customer access token that's accessible on the server if there's a customer login.
- Anchor to datadatadataPartialDeep<CartType, {recurseIntoArrays: true}>PartialDeep<CartType, {recurseIntoArrays: true}>
An object with fields that correspond to the Storefront API's Cart object.
- Anchor to languageCodelanguage
Codelanguage Code LanguageCodeLanguageCode The ISO language code for i18n.
- Anchor to numCartLinesnum
Cart Linesnum Cart Lines numbernumber Maximum number of cart lines to fetch. Defaults to 250 cart lines.
- Anchor to onAttributesUpdateon
Attributes Updateon Attributes Update () => void() => void A callback that is invoked when the process to update the cart attributes begins, but before the attributes are updated in the Storefront API.
- Anchor to onAttributesUpdateCompleteon
Attributes Update Completeon Attributes Update Complete () => void() => void A callback that is invoked when the process to update the cart attributes completes
- Anchor to onBuyerIdentityUpdateon
Buyer Identity Updateon Buyer Identity Update () => void() => void A callback that is invoked when the process to update the buyer identity begins, but before the buyer identity is updated in the Storefront API.
- Anchor to onBuyerIdentityUpdateCompleteon
Buyer Identity Update Completeon Buyer Identity Update Complete () => void() => void A callback that is invoked when the process to update the buyer identity completes
- Anchor to onCreateon
Createon Create () => void() => void A callback that is invoked when the process to create a cart begins, but before the cart is created in the Storefront API.
- Anchor to onCreateCompleteon
Create Completeon Create Complete () => void() => void A callback that is invoked when the process to create a cart completes
- Anchor to onDiscountCodesUpdateon
Discount Codes Updateon Discount Codes Update () => void() => void A callback that is invoked when the process to update the cart discount codes begins, but before the discount codes are updated in the Storefront API.
- Anchor to onDiscountCodesUpdateCompleteon
Discount Codes Update Completeon Discount Codes Update Complete () => void() => void A callback that is invoked when the process to update the cart discount codes completes
- Anchor to onLineAddon
Line Addon Line Add () => void() => void A callback that is invoked when the process to add a line item to the cart begins, but before the line item is added to the Storefront API.
- Anchor to onLineAddCompleteon
Line Add Completeon Line Add Complete () => void() => void A callback that is invoked when the process to add a line item to the cart completes
- Anchor to onLineRemoveon
Line Removeon Line Remove () => void() => void A callback that is invoked when the process to remove a line item to the cart begins, but before the line item is removed from the Storefront API.
- Anchor to onLineRemoveCompleteon
Line Remove Completeon Line Remove Complete () => void() => void A callback that is invoked when the process to remove a line item to the cart completes
- Anchor to onLineUpdateon
Line Updateon Line Update () => void() => void A callback that is invoked when the process to update a line item in the cart begins, but before the line item is updated in the Storefront API.
- Anchor to onLineUpdateCompleteon
Line Update Completeon Line Update Complete () => void() => void A callback that is invoked when the process to update a line item in the cart completes
- Anchor to onNoteUpdateon
Note Updateon Note Update () => void() => void A callback that is invoked when the process to add or update a note in the cart begins, but before the note is added or updated in the Storefront API.
- Anchor to onNoteUpdateCompleteon
Note Update Completeon Note Update Complete () => void() => void A callback that is invoked when the process to add or update a note in the cart completes