mohitkyadav / react-pagination-nav

Pagination navbar component for react

Home Page:https://www.npmjs.com/package/react-pagination-nav

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

React Pagination Navbar

npm node-current npm

Demo

Usage

Install the package

npm i react-pagination-nav

import the package

import ReactPaginationNav from 'react-pagination-nav'
const MyComponent = () => {
  const [currentPage, setCurrentPage] = React.useState(1)
  
  return (
    <div className="App">
      <ReactPaginationNav
        className="my-pagination-nav-bar-class"
        pageCount={9}
        visiblePages={5}
        currentPage={currentPage}
        goToNextPage={() => setCurrentPage(currentPage + 1)}
        goToPreviousPage={() => setCurrentPage(currentPage - 1)}
        goToPage={(newPage) => setCurrentPage(newPage)}
        PrevNextButton={({ direction, onClick }) => <CustomButton onClick={onClick}>{direction === 'prev' ? '<' : '>'}</CustomButton>}
        PageButton={({ page, active, onClick }) => <CustomButton onClick={onClick} active={active}>{page + 1}</CustomButton>}
      />
    </div>
  )
}

props

  • className πŸ‘‰ :optional: custom class name for the container
  • pageCount πŸ‘‰ total pages
  • visiblePages πŸ‘‰ :optional, default 5: number of visible pages, output would be same for any even number and number + 1
  • isPreviousBtnHidden πŸ‘‰ :optional, if true previous button is hidden
  • isNextBtnHidden πŸ‘‰ :optional, if true next button is hidden
  • currentPage πŸ‘‰ current active page
  • goToNextPage πŸ‘‰ :funtion: called when clicked on right arrow button
  • goToPreviousPageπŸ‘‰ :funtion: called when clicked on left arrow button
  • goToPage πŸ‘‰ :funtion: called when clicked on a page number
  • PrevNextButton πŸ‘‰ :optional component: a button component for the prev and next buttons
  • PageButton πŸ‘‰ :optional component: a button component for the page buttons
  • theme πŸ‘‰ :optional: default 'dark', can either be set to 'light' or 'dark'

Author

GH

Discord

License

MIT Licensed. Copyright (c) Mohit Kumar Yadav 2020.

NPM

About

Pagination navbar component for react

https://www.npmjs.com/package/react-pagination-nav

License:MIT License


Languages

Language:JavaScript 84.1%Language:SCSS 15.9%