R
R
RomanSS2018-03-15 16:37:39
JavaScript
RomanSS, 2018-03-15 16:37:39

ReactJs how to pull the object to which the event is attached?

Tell me how you can pull out the object to which the event is attached?
For example:

handleTouchStart = (e) => {
  // как вытащить ссылку на объект div к которому привязано событие onTouchStart? 
  // e.target - вытаскивает объект на котором нажали в данном случае будет h1
}
 render () {
     return <div onTouchStart={this.handleTouchStart}><h1>Контент</h1></div>;
 }

And the second question, how to remove this error in react when trying to call preventDefault()? I do not want to bind an event bypassing the react.
"[Intervention] Unable to preventDefault inside passive event listener due to target being treated as passive. See https://www.chromestatus.com/features/5093566007214080 "

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim, 2018-03-15
@RomanSS

e.currentTarget

B
bugagashnik, 2018-03-15
@bugagashnik

by preventDefault: Link
Read immediately the answer there.
By the way, what is your goal? Maybe I can suggest another implementation. For example, if you want, depending on what you clicked, to divide in your function, then it is better to pass some parameter in the function call.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question