Create React App
Type the following command to create a new react app:
npx create-react-app demo
Now, go to the project folder:
cd demo
Now, update default App.js with below code snippet
src\App.js
import React, { Component } from 'react'; class App extends Component { constructor(props) { super(props); this.handleClick = this.handleClick.bind(this); } handleClick = (event) => { alert(event.type); } render() { return ( <div> <div className="text-center"> <button className="btn btn-secondary" onClick={this.handleClick}> Click Me </button> </div> </div> ); } } export default App;
Most Helpful This Week
How to pass data from child component to its parent in ReactJS?
Integrate Bootstrap with ReactJS Application
How to show hide component on Click in React JS?
Embed JavaScript Expressions in JSX
React JSX
3 Different Examples - How State Works in React?
What is state in React?
How to pass an Argument to a Method used inside JSX expression?
React JS Count number of checkboxes are checked
Check checkbox is Checked or Unchecked