Which of the following code will correctly handle an event inside a function component?
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
This question is part of this quiz :
Event Handling in React