DEV Community 👩‍💻👨‍💻

Discussion on: Event Capturing and Bubbling in React

Collapse
 
varuns924 profile image
Varun S

Very useful article! Can you explain further what you mean by "writing your data into the event object in one handler and read it in another one, so you can pass to handlers on parents [sic] information about the processing below"? Why wouldn't you just write the data and read it in a single handler?

Collapse
 
eladtzemach profile image
Elad Tzemach Author • Edited on

I'm happy to hear you have found this article to be useful!

In regards to your question - imagine you have the following:

<div onClick=...>
   <span id="1" onClick=...> ... </span>
   <span id="2" onClick=...> ... </span>
   <span id="3" onClick=...> ... </span>
</div>
Enter fullscreen mode Exit fullscreen mode

If you want the onClick of both the span and div to be triggered when you click on the span, except for when it's the span with id of 2, how can you achieve that?

My suggestion was that one option is to write information to the event object of that span, so then the div event handler can read it, see that it's the span with id of 2, and then not trigger its own event handler.

I hope it makes sense!

Collapse
 
varuns924 profile image
Varun S

Yes, I now see the application, thank you!

Collapse
 
aderchox profile image
aderchox

How do you write information to the event object? With event.someProp = value?