Skip to content

Commit

Permalink
Improve logic of reset pagination in the TaskList component
Browse files Browse the repository at this point in the history
  • Loading branch information
willemarcel committed May 11, 2021
1 parent 0084afa commit 0595f22
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions frontend/src/components/taskSelection/taskList.js
Original file line number Diff line number Diff line change
Expand Up @@ -394,10 +394,12 @@ function PaginatedList({
}: Object) {
const [page, setPage] = useQueryParam('page', NumberParam);
const lastPage = howManyPages(items.length, pageSize);
// change page to 1 if the page number is not valid
if (items && page && page > lastPage) {
setPage(1);
}
// reset page number to 1 if it is not valid any more
useEffect(() => {
if (items && page > 1 && page > lastPage) {
setPage(1);
}
}, [items, page, lastPage, setPage]);

const latestItems = useRef(items);
useEffect(() => {
Expand Down

0 comments on commit 0595f22

Please sign in to comment.