Created at
Capture phase events
In rare cases, you might need to catch all events on child elements, even if they stopped propagation. For example,
maybe you want to log every click to analytics, regardless of the propagation logic. You can do this by adding Capture
at the end of the event name:
<div
onClickCapture={() => {
/* this runs first */
}}
>
<button onClick={(e) => e.stopPropagation()} />
<button onClick={(e) => e.stopPropagation()} />
</div>
Each event propagates in three phases:
- It travels down, calling all
onClickCapture
handlers. - It runs the clicked element’s
onClick
handler. - It travels upwards, calling all
onClick
handlers.
Capture events are useful for code like routers or analytics, but you probably won’t use them in app code.