Controlled client-side pagination
Keep the current page and page size in component state while controlling a table.
TanStack · Type Alias
PaginationState is TanStack Table’s feature-specific type for pagination state. It contains a zero-based page index and the number of rows per page.
PaginationState is the feature-specific state shape for TanStack Table pagination. It stores the currently selected zero-based page through pageIndex and the number of rows requested per page through pageSize, and can be used for local state or external atoms.
type PaginationState = {
pageIndex: number
pageSize: number
}| Name | Type | Description |
|---|---|---|
pageIndex | number | Zero-based index of the active page. |
pageSize | number | Number of rows displayed or requested per page. |
An object containing pageIndex and pageSize.
type PaginationState = {
pageIndex: number
pageSize: number
}
const pagination: PaginationState = {
pageIndex: 0,
pageSize: 10,
}Creates a valid pagination state with a zero-based page index and a page size of ten.
Keep the current page and page size in component state while controlling a table.
Use pageIndex and pageSize to identify and fetch a server-side page.
Share pagination state with code outside the table instance.
PaginationState is the state object used for table pagination. Its pageIndex is zero-based, and pageSize specifies how many rows belong to a page.
Follow-up: How would you use it with server-side fetching? Include the pagination object in the query key and use it to request the corresponding page and size.
Use PaginationState when creating local state or an external atom for only the pagination slice. The documentation recommends feature-specific state types such as PaginationState for that purpose.
Follow-up: Why prefer the feature-specific type? It keeps the state contract narrow and aligned with the table feature being controlled.
The state can be controlled externally and supplied back to the table, allowing another owner to react to pagination changes. This is useful when pagination must also drive data fetching.
Follow-up: What should a server-side result provide alongside the requested rows? Return the rows for the requested page and the total row count so the table can derive pagination information.
SortingStateRowSelectionStateinitialStatepaginationonPaginationChangerowPaginationFeature