Utility

usePagination

Pagination logic with page calculation, navigation, and range generation.

import { usePagination } from "saha-ui"

Uses

Manage pagination state and expose helper methods for page navigation and calculations.

Props

NameTypeDescriptionDefault
totalItemsnumberTotal number of items.-
itemsPerPagenumberItems per page.10
initialPagenumberInitial page index.1

Returns

NameDescription
currentPageCurrent page number (1-based).
totalPagesTotal number of pages.
itemsPerPageConfigured items per page.
startIndex / endIndexStart and end item indices for the current page.
pageNumbersArray of page numbers for UI rendering.
nextPage() / previousPage() / goToPage(page)Navigation helpers for changing the page.
setItemsPerPage(count)Update items per page and recalculate pagination.

Example

const pager = usePagination({ totalItems: 120, itemsPerPage: 10 });
pager.nextPage();

Notes

Resets page index to 1 when itemsPerPage changes.
Saha UI - The Modern React Component Library