i have two components: 1.Parent 2.Child there is an event in child component called onChange() which return a value. i want to receive the value which was returned from OnChange() in componentDidMount() in parent component.
Example:
class Parent extends PureComponent {
componentDidMount() {
let value = CHILD.onChange(); //triggered when ever onChange()
}
render(){
return(
<Child />
)
}
}
const Child = () => {
const onChange = () => {
const value = 1
return value;
};
}
onChange()method in your Parent and then pass it as apropin your Child component and execute it there. The value can be saved in the state of the Parent component.