mirror of
https://github.com/vercel/commerce.git
synced 2025-05-18 07:26:59 +00:00
34 lines
852 B
TypeScript
34 lines
852 B
TypeScript
import type { GetCardsHook } from '@commerce/types/customer/card'
|
|
|
|
import { useMemo } from 'react'
|
|
import { SWRHook } from '@commerce/utils/types'
|
|
import useCard, { UseCards } from '@commerce/customer/card/use-cards'
|
|
|
|
export default useCard as UseCards<typeof handler>
|
|
|
|
export const handler: SWRHook<GetCardsHook> = {
|
|
fetchOptions: {
|
|
url: '/api/customer/card',
|
|
method: 'GET',
|
|
},
|
|
useHook: ({ useData }) =>
|
|
function useHook(input) {
|
|
const response = useData({
|
|
swrOptions: { revalidateOnFocus: false, ...input?.swrOptions },
|
|
})
|
|
|
|
return useMemo(
|
|
() =>
|
|
Object.create(response, {
|
|
isEmpty: {
|
|
get() {
|
|
return (response.data?.length ?? 0) <= 0
|
|
},
|
|
enumerable: true,
|
|
},
|
|
}),
|
|
[response]
|
|
)
|
|
},
|
|
}
|