Skip to content

useOffsetPagination ​

Category
Utilities

Hook that defines the logic when pagination

typescript
import { useOffsetPagination } from '@siberiacancode/reactuse';

Usage ​

typescript
const { currentPage, currentPageSize, pageCount, isFirstPage, isLastPage, prev, next } = useOffsetPagination({ total: 100, pageSize: 10, page: 1, onPageChange: (page) => {}, onPageCountChange: (pageCount) => {}, onPageSizeChange: (pageSize) => {} });

Demo ​

Api ​

Parameters

NameTypeDefaultNote
optionsUseOffsetPaginationOptions-- The options for the hook
options.total?number-- The total number of items
options.pageSize?number-- The number of items per page
options.initialPage?number-- The current page
options.onPageChange?({ page, pageSize }: { page: number; pageSize: number }) => void-- The callback function to be invoked when page changes
options.onPageCountChange?({ page, pageSize }: { page: number; pageSize: number }) => void-- The callback function to be invoked when page count changes
options.onPageSizeChange?({ page, pageSize }: { page: number; pageSize: number }) => void-- The callback function to be invoked when page size changes

Contributors ​

Source • Demo