React introduced new static method getDerivedStateFromProps(props, state)
which is called before every render method, but why? Calling it after prop change makes se
I also got that issue. So I set another variable to check is that prop received for the first time.
this.state={flag:true}
In getderivedstatefromprops
static getderivedstatefromprops(props, state){
if(props.<*propName*> && flag){
return({ props.<*propName*>, flag:false})
}
}
if you want to use multiple props values you need to set your if statements (or any other logic) accordingly.