UNPKG

@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.

16 lines (15 loc) 1.6 kB
import { type SWRConfiguration } from 'swr'; import { IUseQueryConfig, APIProcessingHook, GlobalFetchWrapperHook, IUseQueryResponse } from '../@types/global'; /** * A wrapper around the `useSwr` hook that includes a custom `fetch` function, `cacheKey` generator and SWR config. * @template TFunc - A function that returns a Promise with some data from the API. * @template TConfig - A configuration object to be passed to the fetch function. * @param {string} endpointId - The `controller.endpoint` ID * @param {TFunc} fetcher - The function to use for fetching data. * @param {IUseQueryConfig<TFunc, TConfig>} hookConfig - An object containing the `cacheKey`, `params`, `config` and `swrConfig` options. * @param {APIProcessingHook} useProcessing - An optional API processing hook to render. * @param {GlobalFetchWrapperHook<TConfig>} useGlobalFetchWrapper - An optional fetch wrapper hook to render. * @param {SWRConfiguration<unknown | undefined>} globalSwrConfig - Global level SWR config. * @returns {SWRResponse<unknown>} - The response from the `useSwr` hook. */ export declare const useQuery: <TFunc extends (...args: Array<unknown>) => Promise<unknown>, TConfig extends object | undefined, TProcessingResponse>(endpointId: string, fetcher: TFunc, hookConfig?: IUseQueryConfig<TFunc, TConfig, Awaited<ReturnType<TFunc>>> | undefined, useProcessing?: APIProcessingHook<TProcessingResponse> | undefined, useGlobalFetchWrapper?: GlobalFetchWrapperHook<TConfig, TFunc> | undefined, globalSwrConfig?: SWRConfiguration<unknown | undefined>) => IUseQueryResponse<TFunc, TProcessingResponse>;