I\'m developing my first React Native app. What I\'m trying to achieve is to execute a child function from the parent component, this is the situation:
Child
it is in react. i hope it may help you.
class Child extends React.Component {
componentDidMount() {
this.props.onRef(this)
}
componentWillUnmount() {
this.props.onRef(null)
}
method() {
console.log('do stuff')
}
render() {
return Hello World!
}
}
class EnhancedChild extends React.Component {
render() {
return
}
}
class Parent extends React.Component {
onClick = () => {
this.child.method() // do stuff
};
render() {
return (
(this.child = ref)} />
);
}
}
ReactDOM.render( , document.getElementById('root'))
Original Solution:
https://jsfiddle.net/frenzzy/z9c46qtv/
https://github.com/kriasoft/react-starter-kit/issues/909