From f8d69323bdb71661bbff8b97fc6e3257273ed40b Mon Sep 17 00:00:00 2001 From: Luis Alvarez Date: Tue, 25 May 2021 14:19:52 -0500 Subject: [PATCH] Updated useData and util hooks --- framework/commerce/utils/use-data.tsx | 13 +++++++------ framework/commerce/utils/use-hook.ts | 6 +++--- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/framework/commerce/utils/use-data.tsx b/framework/commerce/utils/use-data.tsx index 9224b612c..3bd4e4faf 100644 --- a/framework/commerce/utils/use-data.tsx +++ b/framework/commerce/utils/use-data.tsx @@ -2,10 +2,11 @@ import useSWR, { responseInterface } from 'swr' import type { HookSWRInput, HookFetchInput, - Fetcher, - SwrOptions, HookFetcherOptions, HookFetcherFn, + Fetcher, + SwrOptions, + SWRHookSchemaBase, } from './types' import defineProperty from './define-property' import { CommerceError } from './errors' @@ -14,15 +15,15 @@ export type ResponseState = responseInterface & { isLoading: boolean } -export type UseData = ( +export type UseData = ( options: { fetchOptions: HookFetcherOptions - fetcher: HookFetcherFn + fetcher: HookFetcherFn }, input: HookFetchInput | HookSWRInput, fetcherFn: Fetcher, - swrOptions?: SwrOptions -) => ResponseState + swrOptions?: SwrOptions +) => ResponseState const useData: UseData = (options, input, fetcherFn, swrOptions) => { const hookInput = Array.isArray(input) ? input : Object.entries(input) diff --git a/framework/commerce/utils/use-hook.ts b/framework/commerce/utils/use-hook.ts index da3431e3c..1bf0779c4 100644 --- a/framework/commerce/utils/use-hook.ts +++ b/framework/commerce/utils/use-hook.ts @@ -10,14 +10,14 @@ export function useFetcher() { export function useHook< P extends Provider, - H extends MutationHook | SWRHook + H extends MutationHook | SWRHook >(fn: (provider: P) => H) { const { providerRef } = useCommerce

() const provider = providerRef.current return fn(provider) } -export function useSWRHook>( +export function useSWRHook>( hook: PickRequired ) { const fetcher = useFetcher() @@ -30,7 +30,7 @@ export function useSWRHook>( }) } -export function useMutationHook>( +export function useMutationHook>( hook: PickRequired ) { const fetcher = useFetcher()