Back to React Notes
Topic #26

React Events

React events work like DOM events but are synthetic, attached in JSX with camelCase names. Handling clicks, typing and submits is the core of interactivity.


Just like HTML DOM events, React can perform actions based on user events.

React has the same events as HTML: click, change, mouseover etc.


Adding Events

React events are written in camelCase syntax:

onClick instead of onclick.

React event handlers are written inside curly braces:

onClick={shoot} instead of onclick="shoot()".

React:

<button onClick={shoot}>Take the Shot!</button>

HTML:

<button onclick="shoot()">Take the Shot!</button>

Example:

function Football() {
  const shoot = () => {
    alert("Great Shot!");
  }

  return (
    <button onClick={shoot}>Take the shot!</button>
  );
}

createRoot(document.getElementById('root')).render(
  <Football />
);

Passing Arguments

To pass an argument to an event handler, use an arrow function.

Example:

function Football() {
  const shoot = (a) => {
    alert(a);
  }

  return (
    <button onClick={() => shoot("Goal!")}>Take the shot!</button>
  );
}

createRoot(document.getElementById('root')).render(
  <Football />
);

React Event Object

Event handlers have access to the React event that triggered the function.

In our example the event is the "click" event.

Example:

function Football() {
  const shoot = (a, b) => {
    alert(b.type);
    /*
    'b' represents the React event that triggered the function,
    in this case the 'click' event
    */
  }

  return (
    <button onClick={(event) => shoot("Goal!", event)}>Take the shot!</button>
  );
}

createRoot(document.getElementById('root')).render(
  <Football />
);

This will come in handy when we look at Form in a later chapter.

Want to go beyond the notes?

Join Coding Now Tech Institute's React course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available

React Events – FAQs

Quick answers about learning React Events in React.

This free note from Coding Now Tech Institute explains React Events in React — concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every React topic on Coding Now Tech Institute, including React Events, is 100% free with no signup required.
With focused practice, most students grasp React Events in 1–3 days from these notes; pairing it with Coding Now Tech Institute's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the Coding Now Tech Institute Community (/community) — expert instructors answer within 24 hours.
Call NowEnroll Now