Ad

React OnClick Bind(), Where Is The Click Event?

- 1 answer

I have an element with onClick={this.didSelectReview.bind(this,review)}.

In the didSelectReview-function I would like to stop the click event by calling. e.stopPropagation(). But how can I get the click event e?

Ad

Answer

What .bind() does is that it prepends default arguments in the call. So you will have the original arguments right there in your function:

this.didSelectReview = function(review,clickevent){
    clickevent.stopPropagation();

}

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind

Ad
source: stackoverflow.com
Ad