From c2654b2a553595347d2a47c7f522677afe7624bf Mon Sep 17 00:00:00 2001 From: Ethan Freestone Date: Thu, 16 Nov 2023 14:30:59 +0000 Subject: [PATCH] fix: usePrevNextPagination null safety Occasionally usePrevNextPagination would attempt a numeric operation on an undefined variable `currentPage`. This is now protected against. --- CHANGELOG.md | 1 + lib/hooks/usePrevNextPagination.js | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 597e8232..6c97519d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # Change history for stripes-erm-components ## 9.1.0 In progress +* usePrevNextPagination null safety (yarn test warnings) ## 9.0.0 2023-10-12 * Added useParallelBatchFetch hook diff --git a/lib/hooks/usePrevNextPagination.js b/lib/hooks/usePrevNextPagination.js index fe1c2091..7b7ddf49 100644 --- a/lib/hooks/usePrevNextPagination.js +++ b/lib/hooks/usePrevNextPagination.js @@ -148,7 +148,7 @@ const usePrevNextPagination = ({ // Set up MCL specific props based on page const pagingCanGoNext = currentPage && currentPage < Number(count) / pageSize; const pagingCanGoPrevious = currentPage && Number(currentPage) > 1; - const pagingOffset = (currentPage - 1) * pageSize; + const pagingOffset = currentPage ? (currentPage - 1) * pageSize : 0; const onNeedMoreData = (...args) => { if (args[MCL_NEED_MORE_DATA_PREV_NEXT_ARG_INDEX]) { handlePageChange(args[MCL_NEED_MORE_DATA_PREV_NEXT_ARG_INDEX]);