mirror of
https://github.com/vercel/commerce.git
synced 2025-03-27 15:55:54 +00:00
27 lines
659 B
TypeScript
27 lines
659 B
TypeScript
import { SWRHook } from '@commerce/utils/types'
|
|
import useCustomer, { UseCustomer } from '@commerce/customer/use-customer'
|
|
import type { CustomerHook } from '../types/customer'
|
|
|
|
export default useCustomer as UseCustomer<typeof handler>
|
|
|
|
export const handler: SWRHook<CustomerHook> = {
|
|
fetchOptions: {
|
|
url: '/api/customer',
|
|
method: 'GET',
|
|
},
|
|
async fetcher({ options, fetch }) {
|
|
const data = await fetch(options)
|
|
return data?.customer ?? null
|
|
},
|
|
useHook:
|
|
({ useData }) =>
|
|
(input) => {
|
|
return useData({
|
|
swrOptions: {
|
|
revalidateOnFocus: false,
|
|
...input?.swrOptions,
|
|
},
|
|
})
|
|
},
|
|
}
|