Skip to content

<ReactListPagination>

This component gives you full control over rendering pagination. You get all the computed state and helper functions needed to build a custom pagination layout from scratch.

Heads up!

This component will only work when the paginationMode prop is set to pagination on the root <ReactList> component.

Behavior

The component will return null (render nothing) in the following cases:

  • During initial loading (initialLoading is true)
  • When there are no items (data.length === 0)
  • When there is an error

Props

NameTypeDescription
pageLinksNumberDefines how many pagination buttons should be visible at once. The current (active) page is centered when possible. Default: 5
childrenFunctionOptional. A function that receives the pagination scope object
renderFirstFunctionOptional. Custom render function for the first page button
renderPrevFunctionOptional. Custom render function for the previous page button
renderPagesFunctionOptional. Custom render function for the page numbers container
renderPageFunctionOptional. Custom render function for each page number button
renderNextFunctionOptional. Custom render function for the next page button
renderLastFunctionOptional. Custom render function for the last page button

Using children as function

The recommended way to use this component is with children as a function. This gives you access to all pagination state and navigation functions.

jsx
<ReactListPagination pageLinks={5}>
  {({
    page,
    perPage,
    count,
    pagesCount,
    pagesToDisplay,
    hasNext,
    hasPrev,
    prev,
    next,
    first,
    last,
    setPage,
  }) => (
    <div className="pagination">
      <button onClick={first} disabled={!hasPrev}>
        First
      </button>
      <button onClick={prev} disabled={!hasPrev}>
        Previous
      </button>
      
      {pagesToDisplay.map((pageNum) => (
        <button
          key={pageNum}
          onClick={() => setPage(pageNum)}
          className={pageNum === page ? 'active' : ''}
        >
          {pageNum}
        </button>
      ))}
      
      <button onClick={next} disabled={!hasNext}>
        Next
      </button>
      <button onClick={last} disabled={!hasNext}>
        Last
      </button>
    </div>
  )}
</ReactListPagination>

children callback Props

NameTypeDescription
pageNumberThe current active page number
perPageNumberItems per page
countNumberTotal number of items returned by the API
pagesCountNumberTotal number of pages (calculated as Math.ceil(count / perPage))
pagesToDisplayArrayArray of visible page numbers (based on pageLinks prop)
halfWayNumberHalf of the pageLinks count (used for centering logic)
hasNextBooleanIs there a next page? (page * perPage < count)
hasPrevBooleanIs there a previous page? (page !== 1)
prevFunctionFunction to navigate to the previous page (calls setPage(page - 1))
nextFunctionFunction to navigate to the next page (calls setPage(page + 1))
firstFunctionFunction to navigate to the first page (calls setPage(1))
lastFunctionFunction to navigate to the last page (calls setPage(pagesCount))
setPageFunctionFunction to navigate to a specific page. Pass the page number as an argument

Using render props

Alternatively, you can use individual render props for each part of the pagination UI. Each render function receives the full scope object.

jsx
<ReactListPagination
  pageLinks={5}
  renderFirst={(scope) => (
    <button onClick={scope.first} disabled={!scope.hasPrev}>
      First
    </button>
  )}
  renderPrev={(scope) => (
    <button onClick={scope.prev} disabled={!scope.hasPrev}>
      Previous
    </button>
  )}
  renderPages={(scope) => (
    <div>
      {scope.pagesToDisplay.map((pageNum) => (
        <button
          key={pageNum}
          onClick={() => scope.setPage(pageNum)}
          className={pageNum === scope.page ? 'active' : ''}
        >
          {pageNum}
        </button>
      ))}
    </div>
  )}
  renderPage={(scope) => (
    <button
      onClick={() => scope.setPage(scope.page)}
      className={scope.isActive ? 'active' : ''}
    >
      {scope.page}
    </button>
  )}
  renderNext={(scope) => (
    <button onClick={scope.next} disabled={!scope.hasNext}>
      Next
    </button>
  )}
  renderLast={(scope) => (
    <button onClick={scope.last} disabled={!scope.hasNext}>
      Last
    </button>
  )}
/>

renderPage callback Props

When using renderPage, the scope includes an additional isActive property:

NameTypeDescription
pageNumberThe page number
isActiveBooleanWhether this page is the current page

Default behavior

If no children or render props are provided, the component will render default pagination buttons:

jsx
<ReactListPagination />
// Renders default First, Prev, page numbers, Next, Last buttons