no more state anti-pattern

This commit is contained in:
AllenFang
2018-05-20 16:54:04 +08:00
parent 6c086c3892
commit 4ecf2433d0

View File

@@ -15,16 +15,6 @@ class BootstrapTable extends PropsBaseResolver(Component) {
constructor(props) {
super(props);
this.validateProps();
this.state = {
data: props.data
};
}
componentWillReceiveProps(nextProps) {
this.setState({
data: nextProps.data
});
}
render() {
@@ -42,6 +32,7 @@ class BootstrapTable extends PropsBaseResolver(Component) {
renderTable() {
const {
data,
columns,
keyField,
id,
@@ -74,7 +65,7 @@ class BootstrapTable extends PropsBaseResolver(Component) {
const headerCellSelectionInfo = this.resolveSelectRowPropsForHeader({
onAllRowsSelect: this.props.onAllRowsSelect,
selected: this.props.selected,
allRowsSelected: isSelectedAll(this.state.data, this.props.selected)
allRowsSelected: isSelectedAll(data, this.props.selected)
});
const tableCaption = (caption && <Caption>{ caption }</Caption>);
@@ -94,7 +85,7 @@ class BootstrapTable extends PropsBaseResolver(Component) {
selectRow={ headerCellSelectionInfo }
/>
<Body
data={ this.state.data }
data={ data }
keyField={ keyField }
columns={ columns }
isEmpty={ this.isEmpty() }