In this Discuss thread, Sophie Alpert says this about event handling in React:
We don't guarantee anything about event ordering between React events and native events.
However, I'm curious if it's safe to assume that React "capture" events, such as onClickCapture
will always trigger before any native non-capture events.
For example, can I assume that a click on the React-rendered div in MyComponent
will always log "Clicked the div" before it logs "Clicked the window"?
window.document.addEventListener('click', () => {
console.log('Clicked the window');
}
const MyComponent = () => (
<div onClickCapture={() => console.log('Clicked the div')}>
A Div
</div>
);