DEV Community

Aman Kureshi
Aman Kureshi

Posted on

🖱️ Event Handling in React — Making Your UI Interactive

Event handling in React is how you respond to user actions like clicks, typing, submitting forms, etc. It works similarly to plain JavaScript but with a React-friendly syntax.

👋 Example:
function Button() {
const handleClick = () => {
alert("Button clicked!");
};
return <button onClick={handleClick}>Click Me</button>;
}

📌 Key points:

• Events are written in camelCase: onClick, onChange, onSubmit
• You pass a function, not a string
• React wraps events in a SyntheticEvent for cross-browser consistency

💡 You can also pass arguments:
<button onClick={() => handleClick("Aman")}>Greet</button>

Event handling is the core of creating dynamic and interactive UIs in React. Mastering it gives you full control over user interactions.

Top comments (0)