@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.8 kB
TypeScript
import { SWRInfiniteConfiguration } from 'swr/infinite';
import { APIProcessingHook, GlobalFetchWrapperHook, IUseInfiniteQueryResponse, IUseQueryInfiniteConfig } from '../@types/global';
/**
* A wrapper around the `useSwrInfinite` 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 {IUseQueryInfiniteConfig<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 {SWRInfiniteConfiguration<unknown | undefined>} globalSwrInfiniteConfig - Global level infinite SWR config.
* @returns {IUseInfiniteQueryResponse<TFunc, TProcessingResponse>} - The response from the `useSwrInfinite` hook augmented with the error and processing response.
*/
export declare const useInfiniteQuery: <TFunc extends (...args: Array<unknown>) => Promise<unknown>, TConfig extends object | undefined, TProcessingResponse>(endpointId: string, fetcher: TFunc, hookConfig?: IUseQueryInfiniteConfig<TFunc, TConfig, Awaited<ReturnType<TFunc>>> | undefined, useProcessing?: APIProcessingHook<TProcessingResponse> | undefined, useGlobalFetchWrapper?: GlobalFetchWrapperHook<TConfig, TFunc> | undefined, globalSwrInfiniteConfig?: SWRInfiniteConfiguration<unknown | undefined>) => IUseInfiniteQueryResponse<TFunc, TProcessingResponse>;