【发布时间】:2018-08-07 18:27:24
【问题描述】:
所以我的组件看起来像下面提到的这样。 当组件第一次渲染时,它会设置状态。但是对于第二次调用,道具保存新数据但它从未设置状态。相反,状态具有以前的数据。不确定是什么导致了这种行为。我感兴趣的状态是“数据”
class MuiTable extends React.Component {
constructor(props) {
super(props);
this.state = {
order: 'asc',
orderBy: this.props.columnData[0].id,
selected: this.props.defaultAllSelect !== undefined && this.props.defaultAllSelect ? this.props.data.map(d=> d[this.props.uniqueKey]) : [],
data: this.props.isSortable ? this.props.data.sort((a, b) => (a[this.props.columnData[0].id] < b[this.props.columnData[0].id] ? -1 : 1)) : this.props.data,
page: 0,
rowsPerPage: this.props.rowsPerPage,
uniqueKey: this.props.uniqueKey
};
}
}
【问题讨论】: