onclick react

JavaScript
import React, { Component } from 'react';

class App extends Component {
  
  constructor(props) {
    super(props);
    this.sayHello = this.sayHello.bind(this);
  }

  sayHello() {
    alert('Hello!');
  }
  
  return (
    <button onClick={this.sayHello}>
      Click me!
    </button>
  );
}

export default App;change:
  <button type="button" onClick={this.myFunction(argument)}> myButton </button>
  
to this: 
  <button type="button" onClick={this.myFunction.bind(this, argument)}> myButton </button>function ActionLink() {
  function handleClick(e) {    e.preventDefault();    console.log('The link was clicked.');  }
  return (
    <a href="#" onClick={handleClick}>      Click me
    </a>
  );
}import React from 'react';

const App = () => {
  
const message = () => {
 console.log("Hello World!") 
}

return (
<button onClick={message}> Press me to print a message! </button>
  );
}import React from 'react';

function App() {

  function sayHello() {
    alert('Hello!');
  }
  
  return (
    <button onClick={sayHello}>
      Click me!
    </button>
  );
}

export default App;//Event hadling in react
function ActionLink() {
  function handleClick(e) {
    e.preventDefault();
    console.log('The link was clicked.');
  }

  return (
    <a href="#" onClick={handleClick}>
      Click me
    </a>
  );
}
Source

Also in JavaScript: