how to resolve click for div logging as parent too 2c in react

Solutions on MaxInterview for how to resolve click for div logging as parent too 2c in react by the best coders in the world

we are a community of more than 2 million smartest coders
registration for
employee referral programs
are now open
get referred to google, amazon, flipkart and more
register now
  
pinned-register now
showing results for - "how to resolve click for div logging as parent too 2c in react"
Maja
06 Jan 2018
1var App = React.createClass({
2  handleParentClick: function (e) { 
3    console.log('parent');
4  },
5
6  handleChildClick: function (e) {
7    e.stopPropagation();
8    console.log('child');
9  },
10
11  render: function() {
12    return <div>
13      <p onClick={this.handleParentClick}>
14        <span onClick={this.handleChildClick}>Click</span>
15      </p>
16    </div>;
17  }
18});
19
20ReactDOM.render(<App />, document.getElementById('root'));