Contents of React Interview Questions

Comprehensive collection of React interview questions and answers covering hooks, components, state management, and best practices.

HTML Events vs React Events: What's the Difference?

When working with user interactions, both HTML and React handle events — like clicks, keyboard presses, or form submissions — but they do so in slightly different ways.

Here’s a breakdown of the main differences:

FeatureHTML EventsReact Events
BindingEvents are assigned directly to DOM elements using attributes like onclick, onchange, etc.Events are handled via React's JSX syntax using camelCase like onClick, onChange, etc.
Event SystemNative browser event system.Synthetic Event system (React wraps native events into a cross-browser wrapper).
Case SensitivityAttributes are case-insensitive (onclick, ONCLICK, etc.).Attributes are case-sensitive (onClick must be camelCase).
Event ObjectStandard browser Event object.React's SyntheticEvent object, which normalizes events across different browsers.
Default BehaviorYou must manually call event.preventDefault() or return false (depends on browser).You always call event.preventDefault(), returning false doesn’t work.
Memory EfficiencyNative event handlers are attached individually to each element.React uses event delegation: it attaches a single event listener at the root (document) and delegates events to components, improving performance.

Example:

HTML Event:

<button onclick="alert('Clicked!')">Click Me</button>

React Event:

function App() { function handleClick() { alert('Clicked!'); } return <button onClick={handleClick}>Click Me</button>; }

Quick Summary:

  • React events are synthetic (wrapped and standardized across browsers).
  • React events use camelCase (onClick, onSubmit), while HTML uses lowercase (onclick, onsubmit).
  • React delegates events efficiently to a root element to optimize performance.
  • React provides a consistent SyntheticEvent API regardless of browser differences.