forked from crowetic/commerce
assets
components
config
docs
framework
bigcommerce
api
auth
cart
common
customer
get-customer-id.ts
get-customer-wishlist.ts
index.ts
use-customer.tsx
lib
product
scripts
wishlist
README.md
config.json
fetcher.ts
index.tsx
provider.ts
schema.d.ts
schema.graphql
types.ts
commerce
shopify
lib
pages
public
.editorconfig
.env.template
.gitignore
.prettierignore
CHANGELOG.md
README.md
codegen.json
global.d.ts
license.md
next-env.d.ts
next.config.js
package.json
postcss.config.js
tailwind.config.js
tsconfig.json
yarn.lock
25 lines
683 B
TypeScript
25 lines
683 B
TypeScript
import { SWRHook } from '@commerce/utils/types'
|
|
import useCustomer, { UseCustomer } from '@commerce/customer/use-customer'
|
|
import type { Customer, CustomerData } from '../api/customers'
|
|
|
|
export default useCustomer as UseCustomer<typeof handler>
|
|
|
|
export const handler: SWRHook<Customer | null> = {
|
|
fetchOptions: {
|
|
url: '/api/bigcommerce/customers',
|
|
method: 'GET',
|
|
},
|
|
async fetcher({ options, fetch }) {
|
|
const data = await fetch<CustomerData | null>(options)
|
|
return data?.customer ?? null
|
|
},
|
|
useHook: ({ useData }) => (input) => {
|
|
return useData({
|
|
swrOptions: {
|
|
revalidateOnFocus: false,
|
|
...input?.swrOptions,
|
|
},
|
|
})
|
|
},
|
|
}
|