Answer the question
In order to leave comments, you need to log in
How to bind an event in React?
I want to add an id parameter to the event handler, but leave a reference to the event in order to call stopPropagation().
To do this, I use bind, where I pass event and id. But here's the problem, a completely different event is transmitted, that is, instead of mouse click, I get input. What could be the problem?
<li key={i}>
<a href="##" onClick={this._onClick.bind(this, event, el.id)}>Какой-то текст</a>
</li>
Answer the question
In order to leave comments, you need to log in
Why such a method? Wouldn't it be easier to do this:
constructor(props){
this.handleClick = this.handleClick.bind(this);
}
handleClick() {
return (event, index, value) => { //Твой код}
}
<li key={i}>
<a href="##" onClick={event => this._onClick(event, el.id) }>Какой-то текст</a>
</li>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question