React Pagination Component

5.1.0 · renamed · verified Tue Apr 21

rc-pagination is a highly customizable and flexible React UI component for building pagination controls. While version 5.1.0 is the current stable release under this package name, the project has formally transitioned and is actively maintained as the `@rc-component/pagination` package. This library is renowned for its extensive API, offering deep customization options for appearance and behavior, including support for internationalization, quick page jumpers, page size changers, and custom renderers for individual page items. It serves as the foundational pagination logic for prominent UI libraries such as Ant Design, emphasizing accessibility and performance. Developers initiating new projects or upgrading should use `@rc-component/pagination` for the latest features and ongoing support, as `rc-pagination` is effectively superseded by the renamed package.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates a basic functional React component using `rc-pagination`, managing page state, and showcasing common features like total display, size changer, and quick jumper. It includes the necessary CSS import and uses modern ReactDOM rendering.

import React, { useState } from 'react';
import ReactDOM from 'react-dom/client';
import Pagination from 'rc-pagination';
import type { PaginationProps } from 'rc-pagination';
import 'rc-pagination/assets/index.css'; // Don't forget to import styles!

function App() {
  const [current, setCurrent] = useState(1);
  const totalItems = 100;
  const pageSize = 10;

  const onChange: PaginationProps['onChange'] = (page, pageSize) => {
    console.log(`Page: ${page}, PageSize: ${pageSize}`);
    setCurrent(page);
  };

  return (
    <div style={{ padding: '20px' }}>
      <h1>rc-pagination Example</h1>
      <Pagination
        onChange={onChange}
        current={current}
        total={totalItems}
        pageSize={pageSize}
        showTotal={(total, range) => `${range[0]}-${range[1]} of ${total} items`}
        showSizeChanger
        pageSizeOptions={['10', '20', '30']}
        showQuickJumper={{ goButton: true }}
        locale={{ jump_to: 'Go to', page: 'Page' }}
      />
      <p>Current Page: {current}</p>
      <p>Total Items: {totalItems}</p>
    </div>
  );
}

const container = document.getElementById('root');
if (container) {
  const root = ReactDOM.createRoot(container);
  root.render(<App />);
} else {
  console.error("Root element not found. Please ensure an element with id 'root' exists in your HTML.");
}

view raw JSON →