reactjs / react.dev

The React documentation website
https://react.dev/
Creative Commons Attribution 4.0 International
11.06k stars 7.56k forks source link

Add explanation on React event systems in documentation #2536

Open moongazers opened 5 years ago

moongazers commented 5 years ago

Recently I come across a task to embed a React app into another project. It takes a torturing amount of time to learn the lesson that React events and native events are different in significant ways. This article greatly elaborates on it: https://fortes.com/2018/react-and-dom-events/

I didn't see any related details in event-related documentations in React though. It would save a lot of time for future readers if the documentation could contain the analysis and explanation of these points:

Avoid using addEventListener and rely on React event handlers Listen on document (or window) if you want to receive events after all React handlers. Listen anywhere else in order to receive before React handlers React event handlers will always execute after native capture handlers

Thanks.

moongazers commented 4 years ago

This is changed in React 17. Great! https://reactjs.org/blog/2020/08/10/react-v17-rc.html#changes-to-event-delegation