I have a parent and child compoents and I want to call a parent method in the child component like this:
import Parent from \'./parent.js\';
class Child exte
Try this. Passing the function down as props to the child component.
import Parent from './parent.js';
class Child extends React.Component {
constructor(props) {
super(props);
};
click = () => {
this.props.parentMethod();
}
render() {
Hello Child
}
}
class Parent extends React.Component {
constructor(props) {
super(props);
};
someMethod() {
console.log('bar');
}
render() {
Hello Parent, {this.props.children}
}
}