From 0595f227ee0840ad87bf220c883cfcef3c74aac3 Mon Sep 17 00:00:00 2001 From: Wille Marcel Date: Tue, 11 May 2021 08:15:10 -0300 Subject: [PATCH] Improve logic of reset pagination in the TaskList component --- frontend/src/components/taskSelection/taskList.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/frontend/src/components/taskSelection/taskList.js b/frontend/src/components/taskSelection/taskList.js index 84212d4f0a..c822114d7a 100644 --- a/frontend/src/components/taskSelection/taskList.js +++ b/frontend/src/components/taskSelection/taskList.js @@ -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(() => {