React | Event Handling | Question 8

Last Updated :
Discuss
Comments

Which of the following code will correctly handle an event inside a function component?

JavaScript
function App() {
    const handleClick = () => {
        console.log("Button clicked!");
    };

    return <button onClick={handleClick}>Click Me</button>;
}


The code is correct as it is

this.handleClick = handleClick.bind(this) should be added inside the function

handleClick() should be used in the return statement

handleClick should be passed as this.handleClick

Share your thoughts in the comments