mirror of
https://github.com/vercel/commerce.git
synced 2025-03-14 22:42:33 +00:00
Added a default fetcher
This commit is contained in:
parent
d8de84bed1
commit
883fbcbcb9
@ -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<P extends Provider> = Partial<
|
||||
? (input?: UseCustomerInput<P>) => CustomerResponse<P>
|
||||
: (input: UseCustomerInput<P>) => CustomerResponse<P>
|
||||
|
||||
export const fetcher: HookFetcherFn<Customer | null> = async ({
|
||||
options,
|
||||
fetch,
|
||||
normalize,
|
||||
}) => {
|
||||
const data = await fetch({ ...options })
|
||||
return data && normalize ? normalize(data) : data
|
||||
}
|
||||
export const fetcher = defaultFetcher as HookFetcherFn<Customer | null>
|
||||
|
||||
export default function useCustomer<P extends Provider>(
|
||||
input: UseCustomerInput<P> = {}
|
||||
|
12
framework/commerce/utils/default-fetcher.ts
Normal file
12
framework/commerce/utils/default-fetcher.ts
Normal file
@ -0,0 +1,12 @@
|
||||
import { HookFetcherFn } from './types'
|
||||
|
||||
const defaultFetcher: HookFetcherFn<any> = async ({
|
||||
options,
|
||||
fetch,
|
||||
normalize,
|
||||
}) => {
|
||||
const data = await fetch({ ...options })
|
||||
return data && normalize ? normalize(data) : data
|
||||
}
|
||||
|
||||
export default defaultFetcher
|
@ -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<P extends Provider> = Partial<
|
||||
? (input?: UseWishlistInput<P>) => WishlistResponse<P>
|
||||
: (input: UseWishlistInput<P>) => WishlistResponse<P>
|
||||
|
||||
export const fetcher: HookFetcherFn<Wishlist | null> = async ({
|
||||
options,
|
||||
fetch,
|
||||
normalize,
|
||||
}) => {
|
||||
const data = await fetch({ ...options })
|
||||
return data && normalize ? normalize(data) : data
|
||||
}
|
||||
export const fetcher = defaultFetcher as HookFetcherFn<Wishlist | null>
|
||||
|
||||
export default function useWishlist<P extends Provider>(
|
||||
input: UseWishlistInput<P> = {}
|
||||
|
Loading…
x
Reference in New Issue
Block a user