Skip to content

Commit

Permalink
small fixes to the context
Browse files Browse the repository at this point in the history
  • Loading branch information
shahednasser committed Jun 10, 2024
1 parent 95b518b commit a867672
Showing 1 changed file with 4 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ export const highlights = [
["36", "setItem", "Set the cart's ID in `localStorage` in case it changed."],
["44", "fetch", "If the customer doesn't have a cart, create a new one."],
["48", "process.env.NEXT_PUBLIC_PAK", "Pass the Publishable API key to associate the correct sales channel(s)."],
["61", "fetch", "Retrieve the customer's cart."],
["81", "useCart", "The hook that child components of the provider use to access the cart."]
["62", "fetch", "Retrieve the customer's cart."],
["82", "useCart", "The hook that child components of the provider use to access the cart."]
]

```tsx highlights={highlights}
Expand Down Expand Up @@ -51,19 +51,14 @@ type CartProviderProps = {
children: React.ReactNode
}

export const CartProvider = (
{ children }: CartProviderProps
) => {
export const CartProvider = ({ children }: CartProviderProps) => {
const [cart, setCart] = useState<
HttpTypes.StoreCart
>()
const { region } = useRegion()

useEffect(() => {
if (cart || !region) {
if (cart) {
localStorage.setItem("cart_id", cart.id)
}
return
}

Expand All @@ -83,6 +78,7 @@ export const CartProvider = (
})
.then((res) => res.json())
.then(({ cart: dataCart }) => {
localStorage.setItem("cart_id", dataCart.id)
setCart(dataCart)
})
} else {
Expand Down

0 comments on commit a867672

Please sign in to comment.