CartProvider
Wrap your app inCartProvider to manage cart state. It handles cart creation, persistence, and provides actions through context.
component
High-level hooks
UseuseCartContext inside CartProvider for the simplest cart integration.
addItem automatically creates a new cart if one doesn’t exist yet. If the stored cart is no longer valid (e.g., it expired), it creates a fresh cart and retries.Low-level hooks
Direct control over cart mutations, for use outsideCartProvider.
Types
CartContext
Returned byuseCartContext().
CartContext
SimpleLineItem
Each item in theitems array.
SimpleLineItem
Custom storage
The defaultlocalStorageCartIds stores cart IDs in localStorage keyed by cart-{storeUid}. To use a different storage mechanism, implement the CartIdStorage interface:
Next steps
- Checkout. Convert the cart into an order with payment
- Cart concepts. Understand the cart lifecycle