Event Handling is used to perform actions when a user interacts with the UI.
- Button click
- Mouse hover
- Keyboard typing
- Form submit
- Input change
- onClick()
- onChange()
- onSubmit()
- onMouseOver()
- onKeyDown()
- onDoubleClick()
function App() {
function showMessage() {
alert("Button Clicked");
}
return (
<button onClick={showMessage}>
Click Me
</button>
);
}
export default App;What is Event Handling in React?
Handling user actions like clicks, typing, and form submission.
2. Which naming style is used in React events?
CamelCase.
Example:
onClick3. What is Synthetic Event?
A cross-browser wrapper around native browser events.
4. Why use preventDefault()?
To stop default browser behavior like form refresh.