Skip to content

Commit

Permalink
releases : 1.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
je0ngyun committed Oct 15, 2022
1 parent ffe0f65 commit d5d4227
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 1 deletion.
44 changes: 44 additions & 0 deletions dist/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,66 @@
import * as React from 'react'

interface Props {
/**
* Number of pages to display at once in the pagination bar if it is greater than the total number of pages, the page list is initialized with the total number of pages
*/
numOfPage: number
/**
* Initial value of total number of pages,
* Optional (default 0)
*/
totalPage?: number
}

declare const usePagination: ({ numOfPage, totalPage }: Props) => {
/**
* Number of pages to display at once in the pagination bar if it is greater than the total number of pages, the page list is initialized with the total number of pages
*/
pagelist: number[]
/**
* Go to the next section, the page list becomes changes
*/
goNextSection: () => void
/**
* Go to the before section, the page list becomes changes
*/
goBeforeSection: () => void
/**
* Go to the first section, the page list becomes changes
*/
goFirstSection: () => void
/**
* Go to the last section, the page list becomes changes
*/
goLastSection: () => void
/**
* Go to the next page (currentPage becomes +1)
*/
goNext: () => void
/**
* Go to the before page (currentPage becomes -1)
*/
goBefore: () => void
/**
* Set the total number of pages, used when initializing the number of pages in response to the server side
*/
setTotalPage: React.Dispatch<React.SetStateAction<number>>
/**
* Change the currently selected page number in the pagelist
* If you try to set a value that is not in the page list array, an error is thrown.
*/
setPage: (page: number) => void
/**
* Returns whether the next section exists
*/
hasNextSection: boolean
/**
* Returns whether the before section exists
*/
hasBeforeSection: boolean
/**
* This is the currently selected page, with an initial value of 1
*/
currentPage: number
}

Expand Down
7 changes: 7 additions & 0 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ var usePagination = function usePagination(_ref) {
var section = Math.floor(currentTotalPage / numOfPage);
var rest = currentTotalPage % numOfPage;
var maxSection = rest ? section + 1 : section;
(0, _react.useEffect)(function () {
setCurrentTotalPage(totalPage);
}, [totalPage]);
var pagelist = (0, _react.useMemo)(function () {
if (currentSection === maxSection && rest) {
return Array.from({
Expand Down Expand Up @@ -137,6 +140,10 @@ var usePagination = function usePagination(_ref) {
};

var setPage = function setPage(pageNum) {
if (pageNum < pagelist[0] || pageNum > pagelist[pagelist.length - 1]) {
throw new Error("You cannot set a page to a value that is not in the pagelist");
}

setListRefIndex((pageNum - 1) % numOfPage);
};

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-use-pagination-hook",
"version": "1.0.0",
"version": "1.0.1",
"module": "dist",
"main": "dist",
"types": "dist/index.d.ts",
Expand Down

0 comments on commit d5d4227

Please sign in to comment.