mirror of
https://github.com/vercel/commerce.git
synced 2025-04-24 20:07:50 +00:00
29 lines
747 B
TypeScript
29 lines
747 B
TypeScript
import useCart, { UseCart } from '@commerce/cart/use-cart'
|
|
import { Cart } from '@commerce/types'
|
|
import { SWRHook } from '@commerce/utils/types'
|
|
import { normalizeCart } from '../utils/normalize'
|
|
// import { getCustomerQuery, getCustomerToken } from '../utils'
|
|
|
|
export default useCart as UseCart<typeof handler>
|
|
|
|
export const handler: SWRHook<Cart | null> = {
|
|
fetchOptions: {
|
|
query: 'cart',
|
|
method: 'get',
|
|
},
|
|
async fetcher({ options, fetch }) {
|
|
const data = await fetch<any | null>({
|
|
...options,
|
|
})
|
|
return data ? normalizeCart(data) : null
|
|
},
|
|
useHook: ({ useData }) => (input) => {
|
|
return useData({
|
|
swrOptions: {
|
|
revalidateOnFocus: false,
|
|
...input?.swrOptions,
|
|
},
|
|
})
|
|
},
|
|
}
|