4
0
forked from crowetic/commerce
commerce/framework/shopify/customer/use-customer.tsx
cond0r 800ba45fae
Fetch only first 100 best selling products (#310)
* Fetch only first 250 best selling products

* Update get-all-product-paths.ts

* Update use-customer.tsx
2021-05-24 13:44:38 -03:00

32 lines
860 B
TypeScript

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