Clamp page to max pages (#1403)

This commit is contained in:
WithoutPants 2021-05-20 07:28:42 +10:00 committed by GitHub
parent 81058a7807
commit 0f579076b6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -175,6 +175,14 @@ const RenderList = <
const result = useData(filter);
const totalCount = getCount(result);
const items = getData(result);
const pages = Math.ceil(totalCount / filter.itemsPerPage);
// handle case where page is more than there are pages
useEffect(() => {
if (pages > 0 && filter.currentPage > pages) {
onChangePage(pages);
}
}, [pages, filter.currentPage, onChangePage]);
useEffect(() => {
Mousetrap.bind("right", () => {
@ -364,8 +372,6 @@ const RenderList = <
return;
}
const pages = Math.ceil(totalCount / filter.itemsPerPage);
return (
<>
{renderPagination()}