Hi I'm using vercel's commerce and BC as a provider, having problems with getting the customer addresses via useAddresses hook atm. In vercel's version fetcherInput was cartId (but optional), but in here it is customerId. And in the API docs v3 doesn't require neither of them, but v2 requires customerId. So I'm kinda confused on which to use...
Here is the vercel's GetAddressesHook at address.ts:
export type GetAddressesHook<
T extends CustomerAddressTypes = CustomerAddressTypes
> = {
data: T['address'][] | null
input: {}
fetcherInput: { cartId?: string }
swrState: { isEmpty: boolean }
}
export const handler: SWRHook<GetAddressesHook> = {
fetchOptions: {
url: '/api/customer/address',
method: 'GET',
},
async fetcher({ input: { cartId }, options, fetch }) {
if (!cartId) return null
const url = new URL(options?.url!, 'http://a')
return fetch({
url: url.pathname,
method: options.method,
})
},
useHook:
({ useData }) =>
(input) => {
const { data: cart } = useCart()
const response = useData({
swrOptions: {
revalidateOnFocus: false,
...input?.swrOptions,
},
input: [['cartId', cart?.id]],
})
return useMemo(
() =>
Object.create(response, {
isEmpty: {
get() {
return response.data ?? null
},
enumerable: true,
},
}),
[response]
)
},
}
Hi I'm using vercel's commerce and BC as a provider, having problems with getting the customer addresses via useAddresses hook atm. In vercel's version fetcherInput was cartId (but optional), but in here it is customerId. And in the API docs v3 doesn't require neither of them, but v2 requires customerId. So I'm kinda confused on which to use...
Here is the vercel's GetAddressesHook at address.ts:
Here is my implementation: