Socket
Socket
Sign inDemoInstall

react-responsive-pagination

Package Overview
Dependencies
Maintainers
1
Versions
128
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-responsive-pagination

React component for responsive pagination


Version published
Weekly downloads
7.3K
increased by14.93%
Maintainers
1
Weekly downloads
 
Created
Source

React Responsive Pagination

npm version minzipped size GitHub license test release semantic-release

A React pagination component which intelligently renders to the available width. Styled for Bootstrap 4

Example pagination

How do I use it?

  • Make sure your project is using the Bootstrap 4 CSS styles

  • Include the pagination component in your React project with npm install react-responsive-pagination

  • Import the component with import Pagination from 'react-responsive-pagination'

  • Use the component with <Pagination current={currentPage} total={totalPages} onPageChange={pageChangeHandler} /> (see Usage Example for a more detailed example)

  • See the About Auto Sizing section below for info on some limitations of the auto sizing algorithm.

More details...

Requirements / Compatibility

  • React 16.8 (the one with hooks)

  • Bootstrap 4 CSS styles used in your project

  • Modern browsers only (IE 11 is untested and unlikely to work)

Usage Example

import React, { useState } from 'react';
import Pagination from 'react-responsive-pagination';

function MyApp() {
  const [currentPage, setCurrentPage] = useState(4);

  const totalPages = 17;

  return (
    <Pagination
      current={currentPage}
      total={totalPages}
      onPageChange={setCurrentPage}
    />
  );
}

About Auto Sizing

Auto sizing uses the width of the immediate parent element. For best results make sure the parent element isn't intrinsically sized; that means the width of the parent element shouldn't depend on its contents. If your layout is intrinsic then the pagination component should still fill the space correctly but you may occasionally see inconsistant results or additional renders.

You can choose to override the auto sizing by specifying the maxWidth prop (see Props section below).

The final thing to note is that for very narrow widths the component may exceed the available space - this is to ensure that there's always a usable pagination component.

Props

Prop nameTypeDescription
currentnumberThe current active page. Indexed from 1
totalnumberThe total number of pages
onPageChange(newPage: number) => voidA callback handler which is called when the user clicks a new page, note that the active page will not change unless the current prop is updated to reflect the new page (as in the example above). The newPage value is indexed from 1
maxWidthnumberThe maximum width (in pixels) of the pagination component. Specify a value if you want to override the automatic sizing. Note this width may be exceeded in the case where it's not possible to output a small enough component

Keywords

FAQs

Package last updated on 17 Mar 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc