Below is what I’m currently trying, while this.props.handleClick
works for onClick
attribute in the child component, it doesn’t work when called within the child component method.
class ParentComponent extends React.Component {
constructor(props) {
super(props);
this.handleClick = this.handleClick.bind(this);
}
handleClick(e) {
console.log('It works!');
}
render() {
return (<div><ChildComponent handleClick={this.handleClick} /></div>)
}
}
class ChildComponent extends React.Component {
someFunc() {
this.props.handleClick
}
render() {
return (<button onClick={this.props.handleClick}></button>)
}}
link to the full codes on codepen: https://codepen.io/prieton/pen/ZExWbyY?editors=1111