(newPage: number)
| 261 | }, [query.isFetching, totalPages, currentPage]); |
| 262 | |
| 263 | const onPageChange = (newPage: number) => { |
| 264 | // Page 1 is the only page that can be safely navigated to without knowing |
| 265 | // totalPages; no reliance on server data for math calculations |
| 266 | if (totalPages === undefined && newPage !== 1) { |
| 267 | return; |
| 268 | } |
| 269 | |
| 270 | // If the true count is unknown, we allow navigating past the |
| 271 | // known page range. |
| 272 | const upperBound = countIsCapped |
| 273 | ? Number.MAX_SAFE_INTEGER |
| 274 | : (totalPages ?? 1); |
| 275 | const cleanedInput = clamp(Math.trunc(newPage), 1, upperBound); |
| 276 | if (Number.isNaN(cleanedInput)) { |
| 277 | return; |
| 278 | } |
| 279 | |
| 280 | searchParams.set(PAGE_NUMBER_PARAMS_KEY, String(cleanedInput)); |
| 281 | setSearchParams(searchParams); |
| 282 | }; |
| 283 | |
| 284 | // Have to do a type assertion for final return type to make React Query's |
| 285 | // internal types happy; splitting type definitions up to limit risk of the |
no test coverage detected