onClick Event

by Allie Yu

HTML

<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.4.2/umd/react.production.min.js"></script>
<div id="app"></div>

React

class ShowAlert extends React.Component {
  showAlert() {
    alert("Im an alert");
  }

  render() {
    return <button onClick={this.showAlert}>show alert</button>;
  }
}

const rootElement = document.getElementById("app");
ReactDOM.render(<ShowAlert />, rootElement);