javascript / beginner
Snippet
Handling Click Events
React events are named using camelCase (e.g., onClick). You pass a function as the event handler rather than a string, allowing for direct JavaScript execution.
snippet.js
1
2
3
<button onClick={() => alert('Clicked!')}>Click Me</button>
react
Breakdown
1
onClick={...}
The React attribute used to attach a click listener to the element.
2
() => alert('Clicked!')
An arrow function that executes the alert when the button is clicked.