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
| Name | Type | Description | Default |
|---|---|---|---|
| totalItems | number | Total number of items. | - |
| itemsPerPage | number | Items per page. | 10 |
| initialPage | number | Initial page index. | 1 |
Returns
| Name | Description |
|---|---|
| currentPage | Current page number (1-based). |
| totalPages | Total number of pages. |
| itemsPerPage | Configured items per page. |
| startIndex / endIndex | Start and end item indices for the current page. |
| pageNumbers | Array 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.