Skip to content

Latest commit

 

History

History
38 lines (33 loc) · 1.04 KB

README.md

File metadata and controls

38 lines (33 loc) · 1.04 KB

@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>; 
};