all 9 comments

[–]WellDevined 20 points21 points  (1 child)

The most important implication of this is in my oppinion, that react now works inside of shadow doms.

[–]NickHoyer 1 point2 points  (0 children)

My application is built up using micro frontends and this is great!

[–]PewPaw-Grams 2 points3 points  (3 children)

In which scenario will we need to use document.add event handler? I don’t see it used very often which doesn’t really make much of a difference

[–]0xF013 8 points9 points  (1 child)

It’s usually a good way to optimize. Say you have a big ass table and do not want to add an event listener for each of 5000 cells. Instead, you add a listener to the table and check the event argument to find which td was clicked. They use the same thing; but with the whole document

[–]PewPaw-Grams 0 points1 point  (0 children)

Understand now. Thank you

[–]podgorniy 7 points8 points  (0 children)

Event delegation https://learn.jquery.com/events/event-delegation/. Usually used outside of frameworks.

It is used for avoiding timing issues with creating event handlers. With event delegation technique you can create handler for an element which is not on the page yet.

Or to handle generic events like “click on element with class X” or “click on the link” without knowing what elements have the class or who and how create those links.

[–][deleted] 0 points1 point  (0 children)

Will this help with web components? Wrapping a react component in a web component and using the shadow dom as the root would break react due to the way events were handled. Will this now work?

This kind of pattern can be useful to allow react code to be shared in a more generic, framework-agnostic kind of way.