Skip to content

Commit

Permalink
fix(pagination): fix wrong page (#1867)
Browse files Browse the repository at this point in the history
Co-authored-by: maxin <maxin@growingio.com>
  • Loading branch information
nnmax and maxin committed Feb 28, 2022
1 parent eb5edfa commit 37497f8
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/pagination/hooks/usePagination.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,18 @@ const usePagination = (

const goToPage: ReturnType<typeof usePagination>['goToPage'] = useCallback(
(page, event) => {
if (page) {
if (page > 0) {
setCurrentPage(Math.min(page, maxPages));
}
if (isFunction(onChange)) {
onChange(page, pageSize, event);
if (isFunction(onChange)) {
onChange(page, pageSize, event);
}
}
},
[maxPages, onChange, pageSize, setCurrentPage]
);

useEffect(() => {
if (currentPage > maxPages) {
if (currentPage > maxPages && maxPages > 0) {
goToPage(maxPages, null);
}
}, [maxPages, currentPage, setCurrentPage, goToPage]);
Expand Down

1 comment on commit 37497f8

@vercel
Copy link

@vercel vercel bot commented on 37497f8 Feb 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.