I have a React component that acts as a sortable table. The table header and the table rows are children of a container, and the container is handling the state of the table. When a header is clicked, the data is re-ordered just like it is in this semantic-ui-react example.
handleSort = (clickedColumn) => {
const { column, orders, direction } = this.state
if (column !== clickedColumn) {
this.setState({
column: clickedColumn,
orders: customSort(orders, clickedColumn),
direction: 'ascending',
})
} else {
this.setState({
orders: orders.reverse(),
direction: direction === 'ascending' ? 'descending' : 'ascending',
})}
The first time I click a column header, the first closure runs, and this.setState
changes the state of the container, and triggers the children to receive new props and update accordingly. If I re-click the column header to reverse the order of the data, the second closure runs, and this.setState
updates the state of the container. Accordingly, the child component OverviewTableHeader
updates, but OverviewTableRows
does not.
render() {
const { designers, orders, column, direction } = this.state
if (orders === "loading"){
return <Loading />
}
const tableRows = <OverviewTableRows
designers={designers}
orders={this.state.orders}
/>
debugger
return (
<div className="overview">
<Table selectable fixed sortable>
<OverviewTableHeader sort={this.handleSort} column={column} direction={direction}/>
{tableRows}
</Table>
</div>
)
}
Here's a video of this in action.
In the video, you can see OverviewTableRows
trigger componentWillReceiveProps
and shouldComponentUpdate
the first time setState
is triggered in the parent, but not the second.
I can add all of my code if needed. Is this a bug? Any help is greatly appreciated!