When you attach an event handler function to a DOM element using the native addEventListener()
function, the callback will get an event argument passed to it. Event handler functions in React are also passed an event argument, but it's not the standard Event
instance. It's called SyntheticEvent
, and it's a simple wrapper for native event instances.
Synthetic events serve two purposes in React:
Here's an illustration of the synthetic event in the context of a React component:
In the next section, you'll see how these synthetic events are pooled for performance reasons and the implications of this for asynchronous code.
13.58.247.31