SyntheticEvent

This reference guide documents the SyntheticEvent wrapper that forms part of React's Event System. See the Handling Events guide to learn more.

Overview

Your event handlers will be passed instances of SyntheticEvent, a cross-browser wrapper around the browser's native event. It has the same interface as the browser's native event, including stopPropagation() and preventDefault(), except the events work identically across all browsers.

If you find that you need the underlying browser event for some reason, simply use the nativeEvent attribute to get it. The synthetic events are different from, and do not map directly to, the browser's native events. For example in onMouseLeave event.nativeEvent will point to a mouseout event. The specific mapping is not part of the public API and may change at any time. Every SyntheticEvent object has the following attributes:

boolean bubbles
boolean cancelable
DOMEventTarget currentTarget
boolean defaultPrevented
number eventPhase
boolean isTrusted
DOMEvent nativeEvent
void preventDefault()
boolean isDefaultPrevented()
void stopPropagation()
boolean isPropagationStopped()
void persist()
DOMEventTarget target
number timeStamp
string type

Note:

As of v17, e.persist() doesn't do anything because the SyntheticEvent is no longer pooled.

Note:

As of v0.14, returning false from an event handler will no longer stop event propagation. Instead, e.stopPropagation() or e.preventDefault() should be triggered manually, as appropriate.

Supported Events

React normalizes events so that they have consistent properties across different browsers.

The event handlers below are triggered by an event in the bubbling phase. To register an event handler for the capture phase, append Capture to the event name; for example, instead of using onClick, you would use onClickCapture to handle the click event in the capture phase.

  • Clipboard Events

  • Composition Events

  • Keyboard Events

  • Focus Events

  • Form Events

  • Generic Events

  • Mouse Events

  • Pointer Events

  • Selection Events

  • Touch Events

  • UI Events

  • Wheel Events

  • Media Events

  • Image Events

  • Animation Events

  • Transition Events

  • Other Events


Reference

Clipboard Events

Event names:

Properties:


Composition Events

Event names:

Properties:


Keyboard Events

Event names:

Properties:

The key property can take any of the values documented in the DOM Level 3 Events spec.


Focus Events

Event names:

These focus events work on all elements in the React DOM, not just form elements.

Properties:

onFocus

The onFocus event is called when the element (or some element inside of it) receives focus. For example, it's called when the user clicks on a text input.

onBlur

The onBlur event handler is called when focus has left the element (or left some element inside of it). For example, it's called when the user clicks outside of a focused text input.

Detecting Focus Entering and Leaving

You can use the currentTarget and relatedTarget to differentiate if the focusing or blurring events originated from outside of the parent element. Here is a demo you can copy and paste that shows how to detect focusing a child, focusing the element itself, and focus entering or leaving the whole subtree.


Form Events

Event names:

For more information about the onChange event, see Forms.


Generic Events

Event names:


Mouse Events

Event names:

The onMouseEnter and onMouseLeave events propagate from the element being left to the one being entered instead of ordinary bubbling and do not have a capture phase.

Properties:


Pointer Events

Event names:

The onPointerEnter and onPointerLeave events propagate from the element being left to the one being entered instead of ordinary bubbling and do not have a capture phase.

Properties:

As defined in the W3 spec, pointer events extend Mouse Events with the following properties:

A note on cross-browser support:

Pointer events are not yet supported in every browser (at the time of writing this article, supported browsers include: Chrome, Firefox, Edge, and Internet Explorer). React deliberately does not polyfill support for other browsers because a standard-conform polyfill would significantly increase the bundle size of react-dom.

If your application requires pointer events, we recommend adding a third party pointer event polyfill.


Selection Events

Event names:


Touch Events

Event names:

Properties:


UI Events

Event names:

Note

Starting with React 17, the onScroll event does not bubble in React. This matches the browser behavior and prevents the confusion when a nested scrollable element fires events on a distant parent.

Properties:


Wheel Events

Event names:

Properties:


Media Events

Event names:


Image Events

Event names:


Animation Events

Event names:

Properties:


Transition Events

Event names:

Properties:


Other Events

Event names:

Last updated

Was this helpful?