InterviewHubPRO
Section Overview
Q44

Question 44 of 445

Part 1: Core React, JSX & Component Architecture (1 - 77)

10%
React & Modern Frontend (445 Qs)•Part 1: Core React, JSX & Component Architecture (1 - 77)

How events are different in React?

Handling events in React elements has some syntactic differences:

  1. React event handlers are named using camelCase, rather than lowercase.
  2. With JSX you pass a function as the event handler, rather than a string.

Practical Code Example

jsx
// React events use camelCase and synthetic wrapper for cross-browser consistency:
function Button() {
  function handleClick(e) {
    e.preventDefault(); // Explicit prevention required (cannot return false)
    console.log('Synthetic Event target:', e.target);
  }
  return <a href="#" onClick={handleClick}>Click Me</a>;
}