OnlineCBT Logo OnlineCBT
React Tutorial
REACT · LESSON 5

Event Handling in React

By Ratan Updated: 16 Oct 2026

Attach camelCase event handlers (onClick, onChange, onSubmit) and pass synthetic event arguments.

Level: Beginner to Advanced
Duration: ~60 Mins Deep-Dive

1. Synthetic Events in React

React wraps native browser DOM events in a cross-browser abstraction called SyntheticEvent. This ensures consistent event behavior across Chrome, Firefox, Safari, Edge, and mobile browsers.

2. Event Handling Syntax

In standard HTML, event attributes are lowercase strings (e.g. onclick="handleClick()"). In React JSX:

  • Event names are camelCase (e.g. onClick, onChange, onKeyDown, onSubmit).
  • You pass a function reference directly inside curly braces: onClick={handleClick}.
function SubmitButton() {
  // Event handler definition
  const handleClick = (e) => {
    console.log("Button clicked!", e);
  };

  // Pass function reference (DO NOT call it like handleClick())
  return ;
}

3. Passing Arguments to Event Handlers

To pass custom parameters to an event handler, wrap the invocation in an anonymous arrow function:

function OptionList() {
  const handleSelectOption = (optionLetter, e) => {
    console.log("Selected option:", optionLetter);
  };

  return (
    
); }

4. Preventing Default Browser Actions

In React, returning false from an event handler does not prevent default browser behavior. You must explicitly call e.preventDefault():

function ExamLoginForm() {
  const handleSubmit = (e) => {
    e.preventDefault(); // Prevents page reload
    console.log("Submitting form asynchronously via API...");
  };

  return (
    
); }

📝 Live Lesson Practice

HTML/CSS JavaScript Python C++ C PHP
⌨️ Practice Inputs (लाइव इनपुट भरें) (खाली होने पर RED, भरने पर GREEN underline)
💻 Code Editor (Monaco VS Code Engine)
👀 Live Preview
पता संपर्क करें

+91 7877547686

ई-मेल

onlinecbtportal@gmail.com

हेल्पलाइन नंबर

+91 7877547686


डाउनलोड करने के लिए क्लिक करें
Get it on Google Play

ऐप डाउनलोड करने
के लिए Google Play पर
उपलब्ध है

WhatsApp Chat