Feature: Allow Manual Override of Pagination canNextPage/canPreviousPage#6385
Feature: Allow Manual Override of Pagination canNextPage/canPreviousPage#6385rtablada wants to merge 1 commit into
Conversation
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
| @@ -251,7 +251,14 @@ export function table_getCanPreviousPage< | |||
| TFeatures extends TableFeatures, | |||
| TData extends RowData, | |||
| >(table: Table_Internal<TFeatures, TData>) { | |||
| return (table.atoms.pagination?.get()?.pageIndex ?? 0) > 0 | |||
There was a problem hiding this comment.
Previously this used ?? 0. However this is now updated to use the same defaultPageIndex const as table_getCanNextPage for consistency
| const pagination = table.atoms.pagination?.get() | ||
| const { canPreviousPage, pageIndex } = pagination ?? {} |
There was a problem hiding this comment.
Destructuring before any return condition ensures reactivity for lazy eval frameworks are maintained.
This is important in the case where pageIndex is declared as a lazy getter in frameworks such as Solid/Angular/Ember.
| @@ -0,0 +1,123 @@ | |||
| import { describe, expect, it } from 'vitest' | |||
|
In this, I updated only the React docs. I'm not sure if there is a sync script or existing prompt to sync similar API change docs across all FWs |
🎯 Changes
This adds explicit
canNextPageandcanPreviousPageoptions to Pagination state.In large data scale pagination (news feeds, financial, live updates, etc), counts may not be accurate to whether or not pages are available. In these cases it is common for REST (JSON:API) or GraphQL requests to add information on how to navigate to next/previous pages and whether or not those pages exist.
Alternative
For these cases consumers could use a separate store with fallback to Tanstack pagination atom/state. However this means having to manage two state objects and in cases of Frameworks where signal evaluation is lazy (Ember/Vue/Solid), it can be easy to return before all reactive state are evaluated and be in a situation where a value is not properly observed in the case of fallback behavior.
✅ Checklist
pnpm test:pr.