constructor(props) {
super(props);
this.state = {
myStateVar: []
}
}
static getDerivedStateFromProps(props, state) {
if (props.myStateVar !== state.myStateVar) {
return {
myStateVar: props.myStateVar
}
}
toggle() //Need to call the function each time when we get the props update
return null;
}
toggle() {
this.setState({
otherStateVar: []
})
}
I am migrating my react app from 16.3 to latest. I have a problem where getDerivedStateFromProps() is calling continuously because state is updating in toggle(). I need to call the toggle() when the props got updated
Help me out to resolve the problem.