Learn Before
Concept

Handling Events in React

Handling events with React is similar to handling events on DOM elements.

  • In React, event names are written in camelCase rather than lowercase.
  • Additionally, in React, we can pass functions as event handlers instead of strings.
<button onClick={activateLasers}> Activate Lasers </button>
  • To prevent default behavior we cannot return false, we need to call preventDefault()
<button onClick={e=>e.preventDefault()}> Activate Lasers </button>

The e value is a synthetic event is a synthetic event defined by React based W3C spec, you don't need to worried about cross-browser compatibility

0

1

Updated 2023-02-23

Tags

JavaScript Programming Language

Object-Oriented Programming

Programming Language Paradigms

General programming languages

Computing Sciences