on click event button react code example

Example 1: react supported events

onClick 
onContextMenu 
onDoubleClick 
onDrag 
onDragEnd 
onDragEnter 
onDragExit
onDragLeave 
onDragOver 
onDragStart 
onDrop 
onMouseDown 
onMouseEnter 
onMouseLeave
onMouseMove 
onMouseOut 
onMouseOver 
onMouseUp

Example 2: react button onclick

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;

Tags:

Html Example