Fix it being possible to get empty paginated list

This commit is contained in:
Kalle 2023-07-10 10:16:12 +03:00
parent e1b18d710a
commit dad6c8ea2c

View File

@ -32,6 +32,12 @@ export function useSimplePagination<T>({
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,