4
0
forked from crowetic/commerce
commerce/framework/shopify/cart/use-update-item.tsx
Peter Mekhaeil 300d04c1ac
Shopify Provider (#186)
* Start of Shopify provider

* add missing comment to documentation

* add missing env vars to documentation

* update reference to types file
2021-02-12 11:14:16 -03:00

25 lines
560 B
TypeScript

import { useCallback } from 'react'
import { useCommerce } from '../index'
const useUpdateItem = (item: CartItem) => {
const { checkout, client, updateCheckout } = useCommerce()
return useCallback(
async function updateItem({ quantity }: { quantity: number }) {
const lineItemsToUpdate = [{ id: item.id, quantity }]
const cart = await client?.checkout.updateLineItems(
checkout.id,
lineItemsToUpdate
)
updateCheckout(cart)
return cart
},
[checkout, client]
)
}
export default useUpdateItem