Skip to content

Commit

Permalink
Sortable table row re-rendering fix (#456)
Browse files Browse the repository at this point in the history
* Add exhaustive dependencies to data memoized value

* Bump patch
  • Loading branch information
chawes13 authored Oct 30, 2020
1 parent f172bc9 commit 0ea9404
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@launchpadlab/lp-components",
"version": "5.1.0",
"version": "5.1.1",
"engines": {
"node": "^8.0.0 || ^10.13.0 || ^12.0.0"
},
Expand Down
2 changes: 1 addition & 1 deletion src/tables/sortable-table.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ function SortableTable({
)
return sorted
}
}, [ascending, sortPath, sortFunc, valueGetter])
}, [ascending, sortPath, sortFunc, valueGetter, controlled, disableSort, disableReverse, unsortedData])

const handleColumnChange = (column) => {
if (column.disabled) return
Expand Down
11 changes: 11 additions & 0 deletions test/tables/sortable-table.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,3 +324,14 @@ test('`valueGetter` column can be the initial column and is sorted ascending', (
expect(myValueGetter).toHaveBeenCalled()
})

test('table data is updated when data prop changes', () => {
const newTableData = [{ name: 'Kortney' }]
const wrapper = mount(
<SortableTable data={tableData}>
<Column name="name" />
</SortableTable>
)
expect(wrapper.find('td').first().text()).toEqual('Kim')
wrapper.setProps({ data: newTableData })
expect(wrapper.find('td').first().text()).toEqual('Kortney')
})

0 comments on commit 0ea9404

Please sign in to comment.