Skip to content

usePagination, a hook to deal with the "feed" line pagination and "race condition" problem.

License

Notifications You must be signed in to change notification settings

cumtflyingstudio/usePagination

Repository files navigation

@flying-studio/use-pagination

npm version

import usePagination from "@flying-studio/use-pagination";
const { data, loading, error, run, refresh, fetchData } = usePagination(
  (currPage) => request(currPage)
);

quick start

npm i @flying-studio/use-pagination
yarn add @flying-studio/use-pagination
pnpm add @flying-studio/use-pagination

API

declare const usePagination: <T>(paginationRequest: (currPage: number) => Promise<T[]>, option?: {
    idPropertyName: string;
    initialPage: number;
    beforeAllRequest: (currPage: number) => number;
    afterAllRequest: (list: T[]) => void;
} | undefined) => {
    data: T[];
    loading: boolean;
    error: boolean;
    run: (currPage?: number) => void; // with page++
    refresh: () => void; // reload the list with page 1
    fetchData: (type: string) => Promise<{
        id: any;
        item: T;
    }[] | undefined>; 
};

About

usePagination, a hook to deal with the "feed" line pagination and "race condition" problem.

Topics

Resources

License

Stars

Watchers

Forks