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 callpreventDefault()
<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
Related
Rendering in React
State in React Js
Lifecycle Methods in React Class Components
Handling Events in React
React References
React Frameworks
Describing the UI in React
What is true about ReactJS?
Which of the following is true about about React Bootstrap?
Which of the following are true regarding the difference between React events and DOM events?