1.0.8 • Published 2 years ago

use-pagination-pull v1.0.8

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

npm

Using hook

const { currentPage, handlePageChange, nextPage, prevPage, range } =
  usePagination({
    initialPage: 1,
    totalPages: 20,
  });

// output;
// range => [1, '...', 3, 4, 5, '...', 20]

 handlePageChange(3)

// currentPage => 3
// range => [1, '...', 2, 3, 4, '...', 20]

Example in React component

import usePagination from "use-pagination";

const { currentPage, handlePageChange, nextPage, prevPage, range } =
  usePagination({
    initialPage: 1,
    totalPages: 20,
  });

<div className="pagination">
  <button onClick={prevPage}>Previous</button>
  {range.map((page, i) => {
    if (typeof page === "string") {
      return (
        <span key={i} className="page">
          {page}
        </span>
      );
    }
    return (
      <button
        key={i}
        className={page === currentPage ? "page active" : "page"}
        onClick={() => handlePageChange(page)}
      >
        {page}
      </button>
    );
  })}
  <button onClick={nextPage}>Next</button>
</div>;

Props | hook usePagination

PropsTypeDescription
totalPagesnumberThe total number of pages
initialPagenumberThe initial page
boundarystringThe boundary
onPageChangefuncThe callback function
modeInfiniteboolThe infinite mode
hiddenBoundaryboolThe hidden boundary

Packages Status 100% 🔃

This is a hook created with Rollup.

npm

Changelog and Roadmap

  • Documentation
  • Testing
  • Initial release

Development

To get running locally:

npm install
npm run storybook

# or

npm run dev

Testing

npm run test

Contributing

Please see our contributing guide

License

MIT License

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago