Generic event-handler typing
Type a handler when no narrower React event type covers the DOM event you receive.
React 19+ · Type Alias
React.SyntheticEvent is the general TypeScript type for React event objects. It follows the DOM Event model while smoothing over browser inconsistencies and exposing the original event through nativeEvent.
React.SyntheticEvent is the TypeScript base type for React event objects. React event objects follow the standard DOM Event shape while smoothing over browser differences, and they expose the original browser event through nativeEvent.
React.SyntheticEvent<T = Element, E = Event>| Name | Type | Description |
|---|---|---|
event | React.SyntheticEvent<T, E> | The React event object delivered to an event handler; generic parameters can describe the native event and current target element. |
function handleClick(event: React.SyntheticEvent<HTMLButtonElement>) {
event.preventDefault();
console.log(event.currentTarget);
}
export default function App() {
return <button onClick={handleClick}>Save</button>;
}The handler receives React’s event object, uses a standard event method, and reads the element associated with the handler.
Type a handler when no narrower React event type covers the DOM event you receive.
Inspect or cancel an interaction using standard event properties and methods.
Reach browser-specific details that are available only on the underlying DOM event.
SyntheticEvent is the base TypeScript type for React events. React event objects provide standard Event properties and methods while addressing browser inconsistencies.
Follow-up: How do you access the browser event? Read the React event’s nativeEvent property, while remembering that its native type may differ from the React event name.
Use preventDefault() to stop the browser’s default action, and stopPropagation() to stop propagation through the React tree. Properties such as defaultPrevented and currentTarget let the handler inspect event state and attachment.
Follow-up: How can you determine whether cancellation already occurred? Check isDefaultPrevented() or the defaultPrevented property.
Type the handler parameter as React.SyntheticEvent with an appropriate element type when a more specific event type is not available. For example, React.SyntheticEvent<HTMLButtonElement> describes an event handled by a button.
Follow-up: When the event is one of React’s specifically documented event types, prefer that narrower type so event-specific fields are available.
EventnativeEventpreventDefaultstopPropagationcurrentTargettargetisDefaultPreventedisPropagationStopped