@rocketmakers/api-swr
Version:
Rocketmakers front-end library for parsing a generated Typescript API client into a set of configurable React hooks for fetching and mutating data.
23 lines (22 loc) • 1.76 kB
TypeScript
import type { APIProcessingHook, FetchWrapper, FirstArg, GlobalFetchWrapperHook, HookRequestMode } from '../@types/global';
/**
* Root hook for fetching data on the client.
* - Used by both `useQuery` and `useMutation`
* - Renders the global API Processing hook.
* @param endpointId The `controller.endpoint` formatted endpoint ID
* @param mode The hook mode (either `query` or `mutation`)
* @param fetchConfigArg The fetch config to be sent as the second arg to the fetch method
* @param fetcher The fetch method for performing the request
* @param paramsArg The fetch params to be sent as the first arg to the fetch method
* @param useApProcessing The global API Processing hook if defined.
* @param globalFetchWrapperHook An optional hook which returns a wrapper around the fetcher method.
* @param localFetchWrapper An optional hook specific fetch wrapper function to use instead of the global hook.
* @returns a client side fetch function and some other useful state (including the response from the processing hook)
*/
export declare const useClientFetch: <TFunc extends (...args: Array<unknown>) => Promise<unknown>, TConfig extends object | undefined, TProcessingResponse>(endpointId: string, mode: HookRequestMode, fetchConfig: TConfig | undefined, fetcher: TFunc, paramsArg?: Partial<FirstArg<TFunc>> | undefined, useApProcessing?: APIProcessingHook<TProcessingResponse> | undefined, globalFetchWrapperHook?: GlobalFetchWrapperHook<TConfig, TFunc> | undefined, localFetchWrapper?: FetchWrapper<TFunc, TConfig> | undefined) => {
processingResponse: TProcessingResponse | undefined;
clientFetch: (execParams?: Partial<FirstArg<TFunc>> | undefined) => Promise<unknown>;
data: unknown;
error: unknown;
isLoading: boolean;
};