I have a react component in which I need to call a method after the state changes in the getDerivedStateFromProps. Let's say I have a method foo to be called after the state changes in the getDerivedStateFromProps.
//state
state: {
"a": "",
"b": ""
}
static getDerivedStateFromProps(nextProps, currentState){
if(nextProps.show){
// nextProps.foo() function to be called after the state changes to "a": "Apple","b": "Ball"
return {
"a": "Apple",
"b": "Ball"
}
}
}
//The function in parent component
foo = () => {
console.log("Function called")
}