Added a default fetcher

This commit is contained in:
Luis Alvarez 2021-02-11 13:35:17 -05:00
parent d8de84bed1
commit 883fbcbcb9
3 changed files with 16 additions and 16 deletions

View File

@ -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> = {}

View 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

View File

@ -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> = {}