Skip to main content

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.

initialCartCart
Description

Initial cart used before hydrating it from IndexedDB.

namespacestring
Description

Namespace of the cart. Used to avoid cart colisions in IndexedDB.

onItemAdd(newItem: Item, oldItem?: Item) => void
Description

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) => void
Description

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.

Didn't find your answers? Ask the Community. For documentation suggestions, submit your feedback.

JOIN THE COMMUNITY

ON THIS PAGE