From the course: Master React 19, Build Ecommerce Solutions, and Prepare for Interviews with TypeScript, Next.js, and Remix

Unlock this course with a free trial

Join today to access over 25,500 courses taught by industry experts.

Basic event handling: Click

Basic event handling: Click

A user interacts with the web application using clicks, keyboard input and other likewise actions. And these user actions which make the application respond are called events. Just like HTML DOM events, React can perform actions based on the user events. React allows developers to handle these events using a declarative approach which makes the event handling easier to create interactive and dynamic user interfaces. Let's begin with how we can handle a click event in react application. So let me go to the app.js file and add a button with label click me. Let's save and check and the button is rendered. Now to handle a click event, I will add the on click attribute to the button and assign the handleClick function to it. Then I will create a function called handleClick and add a console log with the text button clicked. Let's check again. I'll open the browser console. Here you can see a warning which states that invalid event handler property onClick is displayed. The reason is we…

Contents