This library is still in development and is available only for internal usage at VTEX.
Skip to main content

Pagination

Version: 0.134.0

Pagination

The pagination component allows the user to move back and forth between pages, showing the number of items on the page and in the rest of the collection.

Usage

import { Pagination, usePaginationState } from '@vtex/admin-ui'

function Example() {
const state = usePaginationState({ pageSize: 5, total: 35 })

return <Pagination state={state} />
}

Examples

Loading

Loading...

Query string pagination

You can persist the pagination state within the browser's query params using the useQueryPaginationState hook, instead of usePaginationState. Both hooks are used in the same way. The application should be wrapped by QueryStateProvider.

Watch how your url changes.

Loading...

Actions

Loading...
caution

Be careful when using the setTotal action, because if you set the total to a smaller value it may lead your current page to an invalid one.

Internationalization

Loading...

Props

NameTypeDescriptionRequiredDefault
stateUsePaginationReturnComponent State-
loadingbooleanWhether the table is loading or not🚫false

State

The pagination state object is composed of the currentPage prop and the range prop. The currentPage represents the current page as the name says, and the range is an array that contains two numbers with the first and the last items positions of the current page.

usePaginationState parameters

NameTypeDescriptionRequiredDefault
pageSizenumberAmount of items that will be displayed in a page-
totalnumberTotal amount of items in a collection🚫pageSize value
stateReducer(state: PaginationState, action: PaginationAction) => PaginationStateOptional way to provide a function to be used inside usePagination hook useReducer🚫usePagination hook default reducer
initialPagenumberThe initial state of pagination🚫1

useQueryPaginationState parameters

NameTypeDescriptionRequiredDefault
pageSizenumberAmount of items that will be displayed in a page-
totalnumberTotal amount of items in a collection🚫pageSize value
stateReducer(state: PaginationState, action: PaginationAction) => PaginationStateOptional way to provide a function to be used inside usePagination hook useReducer🚫usePagination hook default reducer

UsePaginationReturn

This represents the type of the props returned by both usePaginationState and useQueryPaginationState.

NameTypeDescriptionRequiredDefault
numberOfPagesnumberThe total number of pages-
currentPagenumberThe current page state-
range[number, number]It represents the positions of the first and last items in the page-
totalnumberIt represents the total number of items-
prevDisabledbooleanWhether the navigation to the previous page is disabled or not-
nextDisabledbooleanWhether the navigation to the next page is disabled or not-
paginate(args: PaginationActionType) => voidThe initial state of pagination-

PaginationActionType

export type PaginationActionType =
| {
type: 'next' | 'prev' | 'reset'
}
| {
type: 'setTotal'
total: number
}
| {
type: 'navigate'
page: number
}