{ "some_product": { "name": "Some Product", "sku": "some_product", "price": 400, "currency": "USD", "id": "some_product", "quantity": 5, "value": 750, "formattedValue": "$7.50" } }
use-shopping-cart
loadCart()
loadCart()
loadCart(cartData, shouldMerge = true)
allows you to load a previously created cart to the current cart.
Params
cartData
- Previously created cart details data
shouldMerge
- If true
, merges different cartDetails data together. If false, replaces cart with cartData
import React, { useEffect } from 'react'import { useShoppingCart } from 'use-shopping-cart'export function LoadCart({ product }) { const { loadCart } = useShoppingCart() // Make an API request to your backend with useEffect() useEffect(async () => { const cartData = await getData() loadCart(cartData) }, []) return <YourComponent />}export default LoadCart
The above example is the ideal use-case for loadCart()