properly initialize state in lifecycle.js (#1707)

This commit is contained in:
Yurui Zhang 2019-12-05 14:40:51 -05:00 committed by Tanner Linsley
parent 22c703391c
commit f8563affb5
2 changed files with 17 additions and 13 deletions

View File

@ -32,17 +32,6 @@ export default class ReactTable extends Methods(Lifecycle(Component)) {
this.resizeColumnStart = this.resizeColumnStart.bind(this)
this.resizeColumnEnd = this.resizeColumnEnd.bind(this)
this.resizeColumnMoving = this.resizeColumnMoving.bind(this)
this.state = {
page: props.defaultPage,
pageSize: props.defaultPageSize,
sorted: props.defaultSorted,
expanded: props.defaultExpanded,
filtered: props.defaultFiltered,
resized: props.defaultResized,
currentlyResizing: false,
skipNextSort: false,
}
}
render () {

View File

@ -1,7 +1,22 @@
export default Base =>
class extends Base {
UNSAFE_componentWillMount () {
this.setStateWithData(this.getDataModel(this.getResolvedState(), true))
constructor (props) {
super(props)
const defaultState = {
page: props.defaultPage,
pageSize: props.defaultPageSize,
sorted: props.defaultSorted,
expanded: props.defaultExpanded,
filtered: props.defaultFiltered,
resized: props.defaultResized,
currentlyResizing: false,
skipNextSort: false,
}
const resolvedState = this.getResolvedState(props, defaultState)
const dataModel = this.getDataModel(resolvedState, true)
this.state = this.calculateNewResolvedState(dataModel)
}
componentDidMount () {