Reputation: 563
How to make sure that the store is already updated and I can invoke a function that needs the updated store?
Upvotes: 0
Views: 1179
Reputation: 563
I used shouldComponentUpdate
shouldComponentUpdate(nextProps) {
if(this.props.someArray.length !== nextProps.someArray.length) {
/* some function here */
return true;
}
return false;
}
Upvotes: 0
Reputation: 8102
Once you update the store. You can get updated global state within connected component in componentWillReceiveProps
like this :
componentWillReceiveProps(nextProps){
//invoke function with updated store
//this.foo(nextProps)
console.log(this.props); // prevProps
console.log(nextProps); // currentProps after updating the store
}
And you can also use getDerivedStateFromProps
static getDerivedStateFromProps(nextProps, prevState) {
}
Upvotes: 2