loading

React Events


React, like HTML DOM events, can trigger actions in response to user events.

React supports the same events as HTML, including click, change, and mouseover.


Adding Events

—— TEXT LAKHVU —-

React:

—— EXAMPLE LAKHVU —-

HTML:

—— EXAMPLE LAKHVU —-

Example:

Include the shoot function into the Football component:

—— EXAMPLE LAKHVU —-

Passing Arguments

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

Example

Send “Goal!” as an argument to the shoot function, utilizing the arrow function:

—— EXAMPLE LAKHVU —-

React Event Object

Event handlers can access the React event that initiated the function.

In our example, the event is called “click”.

Example

Arrow Function: Manually sending the event object.

—— EXAMPLE LAKHVU —-

This will be useful when we look at Form in a later chapter.

Share this Doc

React Events

Or copy link

Explore Topic