CartProvider
CartProvider is a React component that wraps an entire app, providing it with the necessary context to run cart operations, such as addItem, removeItem, etc. (see useCart for more information).
Import​
import { CartProvider } from '@faststore/sdk'
Usage​
import { CartProvider } from '@faststore/sdk'
function App () {
return (
<CartProvider mode="pure">
{children}
</CartProvider>
)
}
Props​
mode*'optimistic' | 'pure'Description
Cart operation mode.
initialCartCartDescription
Initial cart used before hydrating it from IndexedDB.
namespacestringDescription
Namespace of the cart. Used to avoid cart colisions in IndexedDB.
onItemAdd(newItem: Item, oldItem?: Item) => voidDescription
Callback function called when an item is added to cart.
onItemRemove(item?: Item) => void;Description
Callback function called when an item is removed from cart.
onItemUpdate(newItem: Item, oldItem?: Item) => voidDescription
Callback function called when an item is updated.
onValidateCart(cart: Cart) => Promise<Cart | null>Description
Callback function called whenever the cart changes. Available for optimistic mode only.