Pagination
Moves between pages of a list and shows which one is open. Set `hasUnknownPageCount` for cursor APIs that never report a total.
not-compliant
- Overview
- Props
Basic usage
Unknown page count
Some backends paginate with an opaque cursor and report only whether a next page
exists — never a total. Set hasUnknownPageCount to page through those lists:
pageCount becomes a lower bound rather than the real total, and a
non-interactive … marks that more pages may follow.
pageCount still has to cover every page the user can reach — the last page is
always pageCount - 1. So while more pages exist, pass the pages you have
loaded plus one for the next page the backend says exists:
<Pagination
page={page}
pageCount={loadedPages.length + (hasNextPage ? 1 : 0)}
hasUnknownPageCount={hasNextPage}
onChange={handleChange}
/>
Numbers then appear as the user walks forward — [1] 2 … becomes 1 [2] 3 …,
and reaching the last page drops both the … and the next button, since the
total is finally known.
With a forward-only cursor you can only fetch the page after the last one you
loaded. Keep pageCount at one past your loaded pages so no button points
further ahead than a single request — otherwise clicking a number would need to
walk several cursors. The trailing … is deliberately not pressable for the
same reason: there is no known last page to jump to.
Grow pageCount as pages load. It caps navigation, so a pageCount that never
grows leaves the user stuck on pageCount - 1.
Alignment
If you want to change the alignment of the pagination component, you can wrap the pagination component into an HStack component and set the sx property "alignSelf".
Align the pagination component to the right:
<HStack
sx={{
alignSelf: "flex-end",
}}
>
<Pagination page={page} pageCount={pageCount} />
</HStack>
Align the pagination component to the center:
<HStack
sx={{
alignSelf: "center",
}}
>
<Pagination page={page} pageCount={pageCount} />
</HStack>
murray and murray/mobile.Pagination props
| Name | Type | Default Value | Description | Usage count |
|---|---|---|---|---|
| debounceTimer | numberundefined | |||
| hasUnknownPageCount | booleanundefined | false | Set when the total is unknown: `pageCount` is only a lower bound and more pages exist beyond it. Renders a non-interactive trailing `...` to say so. For cursor/keyset-paginated lists, where the backend reports "there is a next page" but no total. `pageCount` must still include every reachable page — so while more pages exist, count the loaded ones plus the next one the backend promised. The last page is always `pageCount - 1`. | |
| maxPageItems | numberundefined | 7 | ||
| onChange* | (page: number) => void | |||
| page* | number | |||
| pageCount* | number |