UNPKG

@gravitywelluk/react-hooks

Version:
34 lines (33 loc) 1.49 kB
export declare type SortOrder<T> = Array<[keyof T, "ASC" | "DESC"]>; export interface PaginationState<ResponseObject, FilterOptions> { /** Starting item index of the current page */ offset: number; /** Page size */ limit: number; /** Results sorting */ order?: SortOrder<ResponseObject>; /** Results filtering */ filters?: FilterOptions; } export interface PaginationActions<ResponseObject, FilterOptions> { /** Load the next page */ next: () => void; /** Load the previous page */ previous: () => void; /** Set page size */ setPageSize: (pageSize: number) => void; /** Set sort key and order */ sort: (order: SortOrder<ResponseObject> | null) => void; /** Set filters */ filter: (filters: FilterOptions | null) => void; /** Reset to initial pagination state */ reset: () => void; } export interface Pagination<ResponseObject, FilterOptions> { /** Pagination params for controlling a paginated API endpoint */ params: PaginationState<ResponseObject, FilterOptions>; /** Pagination actions for updating pagination state */ actions: PaginationActions<ResponseObject, FilterOptions>; } /** Custom reducer to handle offset-based pagination of API endpoints in React */ export declare const usePagination: <ResponseObject extends object, FilterOptions extends object = Partial<ResponseObject>>(initialState: PaginationState<ResponseObject, FilterOptions>) => Pagination<ResponseObject, FilterOptions>;