Loan Laux 49bd38fd82
replace customer query with viewer
Signed-off-by: Loan Laux <loan@outgrow.io>
2021-03-31 17:43:42 +04:00

27 lines
674 B
TypeScript

import useCustomer, { UseCustomer } from '@commerce/customer/use-customer'
import { Customer } from '@commerce/types'
import { SWRHook } from '@commerce/utils/types'
import { viewerQuery } from '../utils'
export default useCustomer as UseCustomer<typeof handler>
export const handler: SWRHook<Customer | null> = {
fetchOptions: {
query: viewerQuery,
},
async fetcher({ options, fetch }) {
const data = await fetch<any | null>({
...options,
})
return data.viewer ?? null
},
useHook: ({ useData }) => (input) => {
return useData({
swrOptions: {
revalidateOnFocus: false,
...input?.swrOptions,
},
})
},
}