Skip to content

Conversation

@jeffredodd
Copy link
Contributor

Summary

Adds a new reusable usePagination hook that extracts pagination logic for use across list components.

Changes

  • New usePagination hook with handlers for first/previous/next/last page navigation
  • New extractPaginationMeta utility for parsing pagination headers
  • Null-safety for undefined httpMeta with sensible defaults
  • Comprehensive unit tests (15 tests)

Testing

npm run test -- --run src/hooks/usePagination/

Follow-up PRs

This is PR 1 of 3 for the pagination improvements:

  1. This PR: Add usePagination hook
  2. DataView loading overlay + refactor list components
  3. Fix PayrollConfiguration pagination race condition

Copilot AI review requested due to automatic review settings January 7, 2026 17:17
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a reusable usePagination hook to centralize pagination logic across list components, improving code maintainability and consistency. The hook manages page navigation (first, previous, next, last) and items-per-page changes while extracting pagination metadata from HTTP response headers.

Key changes:

  • New usePagination hook with page navigation handlers and state management
  • extractPaginationMeta utility for parsing x-total-pages and x-total-count headers with null-safe defaults
  • Comprehensive test suite with 15 tests covering state management, edge cases, and header extraction

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.

File Description
src/hooks/usePagination/usePagination.ts Core hook implementation with navigation handlers and metadata extraction
src/hooks/usePagination/usePagination.test.ts Complete test coverage for hook behavior and edge cases
src/hooks/usePagination/index.ts Public API export for hook and utility function

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@serikjensen
Copy link
Member

Left feedback here around potentially moving state to inside the hook rather than passing it in

@jeffredodd jeffredodd force-pushed the jdj/usePagination-hook branch from 8b566cc to 833fd6c Compare January 7, 2026 22:43
- Extract pagination logic into reusable hook
- Add null-safety for undefined httpMeta
- Include comprehensive unit tests
- Add parseHeaderInt helper with parseInt and NaN validation
- Replace non-null assertions with optional chaining in tests
- Add tests for invalid header values (NaN handling)
@jeffredodd jeffredodd force-pushed the jdj/usePagination-hook branch from 833fd6c to 634db48 Compare January 7, 2026 22:44
@jeffredodd
Copy link
Contributor Author

Left feedback here around potentially moving state to inside the hook rather than passing it in

Updated

@jeffredodd jeffredodd merged commit 6add8b3 into main Jan 8, 2026
8 checks passed
@jeffredodd jeffredodd deleted the jdj/usePagination-hook branch January 8, 2026 00:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants