私は、ソート可能なテーブルとして機能するReactコンポーネントを持っています。テーブルのヘッダとテーブルの行はコンテナの子であり、コンテナはテーブルの状態を処理しています。ヘッダーをクリックすると、データはthis semantic-ui-react exampleのように並べ替えられます。Reactの子コンポーネントが新しい小道具を受け取っていないのはなぜですか?
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',
})}
私は列のヘッダーをクリックしてください最初の時間は、最初の閉鎖が実行され、this.setState
は、コンテナの状態を変更し、新しい小道具を受信し、それに応じて更新するために、子どもたちをトリガーします。列のヘッダーを再度クリックしてデータの順序を逆にすると、2番目のクロージャが実行され、this.setState
はコンテナの状態を更新します。したがって、子コンポーネントOverviewTableHeader
は更新されますが、OverviewTableRows
は更新されません。ビデオで
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.
、あなたはOverviewTableRows
トリガーcomponentWillReceiveProps
とshouldComponentUpdate
初めてsetState
が親ではなく、第二にトリガされ見ることができます。
必要に応じてすべてのコードを追加できます。これはバグですか?どんな助けでも大歓迎です!