React Event Handlers

Synthetic events vs Native events.

TypeScript3 min readConcept 53 of 54

The Synthetic Wrapper

When you click a button in React, the event object you receive in onClick is *not* a native browser DOM event.

React intercepts all native events and wraps them in a cross-browser SyntheticEvent. Because of this, TypeScript requires you to use React's specific event types, like React.MouseEvent.

The Mismatch Error

If you try to type a React click handler as e: MouseEvent (the native DOM type), TypeScript will yell at you. The props expect React.MouseEvent<HTMLButtonElement>.

This distinction is crucial when you are mixing vanilla DOM event listeners with React event handlers.

Syntax

tsx import React from "react"; // ❌ Wrong: Native DOM Event function handleClick(e: MouseEvent) { } // ✅ Right: React Synthetic Event + Element Generic function handleClick(e: React.MouseEvent<HTMLButtonElement>) { } export function Button() { return <button onClick={handleClick}>Click Me</button> }

Try it

Observe the difference between typing a native browser event listener and typing a React component's event handler.

// ❌ Native DOM Event Type
function handleNative(e: MouseEvent) {}
<button onClick={handleNative
Types of parameters 'e' and 'event' are incompatible.
}>

// ✅ React Synthetic Event Type
function handleReact(e: React.MouseEvent<HTMLButtonElement>) {}
<button onClick={handleReact}>
Event Interception
Browser DOM
Raw MouseEvent
client.x: 42target: button...browser specific quirks
React rejects this raw type in JSX!
React Wrapper
React Engine
React.MouseEvent
nativeEvent: Raw MouseEventcurrentTarget: HTMLButtonElement...normalized for all browsers
Strictly typed for cross-browser safety.

Check yourself

Pick an answer to lock it in, then read why. Getting one wrong is part of how it sticks.

  1. 1Why does React use `React.MouseEvent` instead of the browser's native `MouseEvent`?

Remember this

  • React uses Synthetic Events, not Native DOM events.
  • Type click events as React.MouseEvent<HTMLElement>.
  • Type form submissions as React.FormEvent<HTMLFormElement>.
  • Inline handlers (onClick={(e) => ...}) are auto-typed by TypeScript.

Done with this concept?

Mark it complete to track your progress. No login needed.