In this article, you will learn about Event Handling in ReactJS and get the answers to the following questions:
- What is Event
- What is SyntheticEvent?
- Why is SyntheticEvent required?
- Event Examples?
- Can we call Multiple functions onClick Event and pass?
1. What is an Event?
An Event is a reaction to user action on UI (User Interface).
Standard events are like,
- OnClick, OnBlur, etc . ..
ReactJS support the following categories of events,
- Clipboard Events
- Composition Events
- Keyboard Events
- Focus Events
- Form Events
- Generic Events
- Mouse Events
- Pointer Events
- Selection Events
- Touch Events
- UI Events
- Wheel Events
- Media Events
- Image Events
- Animation Events
- Transition Events
- Other Events
2. What is SyntheticEvent?
SyntheticEvent is a cross-browser wrapper around the browser's native event.
SyntheticEvent supports all events to adapt on different browsers easily.
For more info, refer https://reactjs.org/docs/events.html.
3. Why is SyntheticEvent required?
As you know, UI is different from browser to browser. That's the same way event understanding is different from browser to browser.
SynthenticEvent passes the event as per the demand of the browser and understanding of the browser. In short, in ReactJS user is not directly interacting with the DOM event, the user is interacting with SyntheticEvent.
4. Event Example
Button Click Event
<button onClick={DispMsg}>Message</button>
You can see the above line of code where on onclick calling DISPMSG function inside curly braces.
Example
MessageDisplay.JS Code
import React from 'react';
function MessageDisplay(){
const DispMsg = (e) => {
e.preventDefault();
alert("Welcome to learn Button Click Event.");
}
return(
//Click on Button to get alert message . .!
<button id="btnMsg" onClick={DispMsg}>Message</button>
);
}
export default MessageDisplay;
App.JS Code
import React from 'react';
import MessageDisplay from './MessageDisplay';
function App() {
return (
<div>
<br/>
<br/>
<br/>
<MessageDisplay></MessageDisplay>
</div>
);
}
export default App;
OUTPUT





Join the conversation! Your thoughts help the community grow.