fix(react-table): Table.Pagination component doesn't update with Table.Body
Closes #543
📝 Description
Updating <Table /> component can be a usual action, as mentioned in #543. However, <Table.Pagination> does not update synchronically with <Table.Body />, which results in two bugs:
-
<Table.Pagination />length doesn't change. So when rows number is larger after the update, some pages can not be selected via<Table.Pagination />. - When rows number is smaller comparing to the previous table, the original page of
<Table.Pagination />is automatically selected and a blank table is showed.3.
This is because:
- The table context
collectionnever updates when rows data change. -
<Pagination />is not properly controlled as it does not receive thepageprop.
⛳️ Current behavior (updates)
#543 described it thoroughly. I've added a new story here so it would be clearer to test.

🚀 New behavior

💣 Is this a breaking change (Yes/No): No
📝 Additional Information
As agreed with @imchell, I will add some test cases to his PR.
Codecov Report
Merging #549 (3421c4f) into main (d3c7f53) will increase coverage by
1.25%. The diff coverage is100.00%.
@@ Coverage Diff @@
## main #549 +/- ##
==========================================
+ Coverage 74.75% 76.00% +1.25%
==========================================
Files 200 200
Lines 3090 3101 +11
Branches 952 956 +4
==========================================
+ Hits 2310 2357 +47
+ Misses 765 729 -36
Partials 15 15
| Impacted Files | Coverage Δ | |
|---|---|---|
| packages/react/src/table/table-pagination.tsx | 85.71% <ø> (+71.42%) |
:arrow_up: |
| packages/react/src/table/table-context.tsx | 84.00% <100.00%> (+2.18%) |
:arrow_up: |
| packages/react/src/card/card.tsx | 100.00% <0.00%> (ø) |
|
| packages/react/src/button/button.tsx | 94.00% <0.00%> (ø) |
|
| packages/react/src/popover/popover-trigger.tsx | 100.00% <0.00%> (ø) |
|
| packages/react/src/dropdown/dropdown-trigger.tsx | 100.00% <0.00%> (ø) |
|
| packages/react/src/utils/collections.ts | 83.07% <0.00%> (+1.53%) |
:arrow_up: |
| packages/react/src/use-pagination/index.ts | 100.00% <0.00%> (+2.43%) |
:arrow_up: |
| packages/react/src/pagination/pagination.tsx | 68.42% <0.00%> (+2.63%) |
:arrow_up: |
| packages/react/src/table/table.tsx | 93.54% <0.00%> (+3.22%) |
:arrow_up: |
| ... and 7 more |
Continue to review full report at Codecov.
Legend - Click here to learn more
Δ = absolute <relative> (impact),ø = not affected,? = missing dataPowered by Codecov. Last update d3c7f53...3421c4f. Read the comment docs.
Fixed here https://github.com/nextui-org/nextui/pull/626