const App = () => {
const handleClick = (event, param) => {
console.log(event);
console.log(param);
};
return (
<div>
<button onClick={event => handleClick(event, 'hello world')}>
Click
</button>
</div>
);
};
export default App;
// Wrong way: This alert fires when the component renders, not when clicked!
<button onClick={alert('You clicked me!')}>
// Correct way:
<button onClick={() => alert('You clicked me!')}>
function Button(){
const [counter , setCounter] = useState(0);
return <button onClick={() => setCounter(counter+1)}>{counter}</button>
}
ReactDOM.render(
<Button />,
document.getElementById('mountNode'),
);
<button onClick={activateLasers}> Activer les lasers
</button>
<button onClick={sayHello}>
Click me!
</button>