diff --git a/framework/commerce/customer/use-customer.tsx b/framework/commerce/customer/use-customer.tsx index f1675a544..4fb9b430b 100644 --- a/framework/commerce/customer/use-customer.tsx +++ b/framework/commerce/customer/use-customer.tsx @@ -5,6 +5,7 @@ import type { UseHookInput, UseHookResponse, } from '../utils/types' +import defaultFetcher from '../utils/default-fetcher' import useData from '../utils/use-data-2' import { Provider, useCommerce } from '..' @@ -27,14 +28,7 @@ export type UseCustomer

= Partial< ? (input?: UseCustomerInput

) => CustomerResponse

: (input: UseCustomerInput

) => CustomerResponse

-export const fetcher: HookFetcherFn = async ({ - options, - fetch, - normalize, -}) => { - const data = await fetch({ ...options }) - return data && normalize ? normalize(data) : data -} +export const fetcher = defaultFetcher as HookFetcherFn export default function useCustomer

( input: UseCustomerInput

= {} diff --git a/framework/commerce/utils/default-fetcher.ts b/framework/commerce/utils/default-fetcher.ts new file mode 100644 index 000000000..25211a689 --- /dev/null +++ b/framework/commerce/utils/default-fetcher.ts @@ -0,0 +1,12 @@ +import { HookFetcherFn } from './types' + +const defaultFetcher: HookFetcherFn = async ({ + options, + fetch, + normalize, +}) => { + const data = await fetch({ ...options }) + return data && normalize ? normalize(data) : data +} + +export default defaultFetcher diff --git a/framework/commerce/wishlist/use-wishlist.tsx b/framework/commerce/wishlist/use-wishlist.tsx index 64bb5a1c1..314f0a1c2 100644 --- a/framework/commerce/wishlist/use-wishlist.tsx +++ b/framework/commerce/wishlist/use-wishlist.tsx @@ -5,6 +5,7 @@ import type { UseHookInput, UseHookResponse, } from '../utils/types' +import defaultFetcher from '../utils/default-fetcher' import useData from '../utils/use-data-2' import { Provider, useCommerce } from '..' @@ -27,14 +28,7 @@ export type UseWishlist

= Partial< ? (input?: UseWishlistInput

) => WishlistResponse

: (input: UseWishlistInput

) => WishlistResponse

-export const fetcher: HookFetcherFn = async ({ - options, - fetch, - normalize, -}) => { - const data = await fetch({ ...options }) - return data && normalize ? normalize(data) : data -} +export const fetcher = defaultFetcher as HookFetcherFn export default function useWishlist

( input: UseWishlistInput

= {}