my App component like as below:
class App extends Component {
clickHandler = () => {
console.log('click');
}
render() {
return (
<div className="App">
<div onClick={this.clickHandler}>Test1</div>
<Person onClick={this.clickHandler}>Test2</Person>
</div>
);
}
}
And this is my Person component:
class Person extends Component {
render() {
return (
<div>{this.props.children}</div>
)
}
}
When i click on Test1 onClick works and show click on console, but when i click on Test2 onClick doesn't work.
how to i handler onClick in parent component? i don't want pass onClick to child component.
onClickto the child component? That's pretty much how React works, although there are different ways to get properties in children.