is a cross-browser wrapper around the browser's native event. Its API is same as the browser's native event, includingSyntheticEvent
andstopPropagation()
, except the events work identically across all browsers. The native events can be accessed directly from synthetic events usingpreventDefault()
attribute.nativeEvent
Let's take an example of
title search component with the ability to get all native event propertiesBookStore
function BookStore() {function handleTitleChange(e) {console.log("The new title is:", e.target.value);console.log('Synthetic event:', e); // React SyntheticEventconsole.log('Native event:', e.nativeEvent); // Browser native evente.stopPropagation();e.preventDefault();}return <input name="title" onChange={handleTitleChange} />;}
List of common synthetic events are:
- onClick
- onChange
- onSubmit
,onKeyDownonKeyUp
,onFocusonBlur
,onMouseEnteronMouseLeave
,onTouchStartonTouchEnd