infinity-fetch - v1.4.0
    Preparing search index...

    Type Alias InfinityFetchConfig<TResponse, TParams, TItem>

    type InfinityFetchConfig<TResponse, TParams extends object, TItem> = {
        fetcher: (params: TParams) => Promise<TResponse>;
        initialParams: TParams;
        isLastPage: (response: TResponse) => boolean;
        getNextParams: (response: TResponse, currentParams: TParams) => TParams;
        getItems: (response: TResponse) => TItem[];
        onStart?: () => void;
        onEnd?: (result: InfinityFetchResult<TItem>) => void;
        onPage?: (items: TItem[], response: TResponse, pageIndex: number) => void;
        maxPages?: number;
        delay?: number;
        retry?: InfinityFetchRetryConfig;
        signal?: AbortSignal;
    }

    Type Parameters

    • TResponse
    • TParams extends object
    • TItem
    Index

    Properties

    fetcher: (params: TParams) => Promise<TResponse>

    The function that fetches a single page

    initialParams: TParams

    Initial parameters for the first request

    isLastPage: (response: TResponse) => boolean

    Returns true when no more pages should be fetched

    getNextParams: (response: TResponse, currentParams: TParams) => TParams

    Returns the params for the next page request

    getItems: (response: TResponse) => TItem[]

    Extracts items from a single page response

    onStart?: () => void

    Optional: called once before the first fetch starts

    onEnd?: (result: InfinityFetchResult<TItem>) => void

    Optional: called once after all pages have been fetched

    onPage?: (items: TItem[], response: TResponse, pageIndex: number) => void

    Optional: called after each page is fetched

    maxPages?: number

    Optional: maximum number of pages to fetch (safety limit)

    delay?: number

    Optional: milliseconds to wait between each page fetch

    Optional: retry failed page fetches

    signal?: AbortSignal

    Optional: signal to abort pagination early and return partial results