React Tutorial #5: Event Handling

In the previous tutorial, you learned about props and state. Now let’s learn how to respond to user actions — clicks, form inputs, and keyboard events. Handling Click Events The most common event is a click. Use the onClick prop: function ClickMe() { function handleClick() { alert("Clicked!"); } return <button onClick={handleClick}>Click me</button>; } Notice: you pass the function reference (handleClick), not a function call (handleClick()). Passing onClick={handleClick()} would call the function immediately when the component renders, not when the button is clicked. ...

July 27, 2026 · 5 min