Event handling in React

State is an internally managed configuration for any component. Let us take this example of creating a simple timer.

Codesanbox State Example

Event Handling Example

Inside a loop, it is common to want to pass an extra parameter to an event handler. For example, if id is the row ID, either of the following would work:

<button onClick={() => deleteRow(id)}>Delete Row</button>
// if you want the event also to be passed
<button onClick={(e) => deleteRow(id, e)}>Delete Row</button>

In both cases, the e aaxrgument representing the React event will be passed as a second argument after the ID. With an arrow function, we have to pass it explicitly, but with bind any further arguments are automatically forwarded.

Handling Events

1.1
Event handling in React State is an internally managed configuration for any component. Let us take this example of creating a simple timer. Codesanbox State Example Event Handling Example Inside a loop, it is common to want to pass an extra parameter to an event handler. For example, if id is the row ID, either of the following would work: <button onClick={() => deleteRow(id)}>Delete Row</button> // if you want the event also to be passed <button onClick={(e) => deleteRow(id, e)}>Delete Row</button> In both cases, the e aaxrgument representing the React event will be passed as a second argument after the ID. With an arrow function, we have to pass it explicitly, but with bind any further arguments are automatically forwarded. Handling Events