UNPKG

@stainless-code/react-paginate

Version:
76 lines (74 loc) 2.22 kB
/** * Options for the `usePaginate` hook. */ interface UsePaginateOptions { /** * The initial number of items per page * * @default 25 */ initialPageSize?: number; /** * The initial page index. * * @default 0 */ initialPageIndex?: number; /** * The minimum number of items required to enable pagination. * * @default 0 */ threshold?: number; } /** * A hook to manage pagination for a list of items. * * @template T - The type of items in the list. * @param {T[]} items - The list of items to paginate. * @param {UsePaginateOptions} [options] - Options for the `usePaginate` hook. * @returns {object} - Pagination state and handlers. */ declare function usePaginate<T>(items: T[], options?: UsePaginateOptions): { canFirstPage: boolean; canLastPage: boolean; canNextPage: boolean; canPrevPage: boolean; changePage: (index: number) => void; changePageSize: (size: number) => void; firstPage: () => void; firstPageIndex: number; lastPage: () => void; lastPageIndex: number; nextPage: () => void; nextPageIndex: number; page: T[]; pageCount: number; pageIndex: number; pages: T[][]; pageSize: number; prevPage: () => void; prevPageIndex: number; resetPage: () => void; shouldPaginate: boolean; }; /** * Divides a list of items into pages. * * @template T - The type of items in the list. * @param {T[]} items - The list of items to paginate. * @param {number} pageSize - The number of items per page. * @param {number} pageIndex - The index of the page to return. * @returns {T[]} - The items for the specified page. */ declare function paginate<T>(items: T[], pageSize: number, pageIndex: number): T[]; /** * Calculates the total number of pages for a list of items. * * @template T - The type of items in the list. * @param {T[]} items - The list of items to paginate. * @param {number} pageSize - The number of items per page. * @returns {number} - The total number of pages. */ declare function getPageCount<T>(items: T[], pageSize: number): number; export { type UsePaginateOptions, getPageCount, paginate, usePaginate };