Reputation: 359
I have component connected to redux store which gets data from props:
const mapStateToProps = state => ({rowData: dataSelector(state)})
The component has its own state:
this.state = {
rowsPerPage: 23,
pageCount: 0,
}
I need to calculate new state.pageCount
when props.rowData
changes. How can i do it?
Upvotes: 0
Views: 176
Reputation: 1973
You can use getSnapshotBeforeUpdate
to determine when the props.rowData
changes by using an if condition. Based on when the value is changed, you can update your state.pageCount
like the way you want.
Upvotes: 1
Reputation: 570
Please create componentWillReceiveProps
componentWillReceiveProps(newProps) {
if(newProps.rowData.length !== this.state.pageCount) {this.setState({pageCount: newProps.rowData.length})}
}
Upvotes: 0