From dad6c8ea2c7d9b3d0ae7cf7c32e0906612b541ec Mon Sep 17 00:00:00 2001 From: Kalle <38327916+Sendouc@users.noreply.github.com> Date: Mon, 10 Jul 2023 10:16:12 +0300 Subject: [PATCH] Fix it being possible to get empty paginated list --- app/hooks/useSimplePagination.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/hooks/useSimplePagination.ts b/app/hooks/useSimplePagination.ts index a12360176..ff4815629 100644 --- a/app/hooks/useSimplePagination.ts +++ b/app/hooks/useSimplePagination.ts @@ -32,6 +32,12 @@ export function useSimplePagination({ const thereIsNextPage = currentPage < pagesCount; const thereIsPreviousPage = currentPage > 1; + // if the list changes from externally it might be that we are on a page that doesn't exist anymore + // setting state inside render looks weird but should be ok + if (itemsToDisplay.length === 0 && currentPage > 1) { + setCurrentPage(1); + } + return { pagesCount, currentPage,