I am trying to create a count function in which I want counter to get increased by 1 when user click on button, but code is getting compiled successfully and react app is showing white blank page.
App.js:
import './App.css';
import Count from './Components/Count';
function App() {
return (
<div className='App'>
<Count></Count>
</div>
);
}
export default App;
Count.js (inside src/Components Folder):
import React, {Component} from "react";
class Count extends Component{
constructor(){
super();
this.state({
count:0
});
}
count(){
this.setState({
count : this.state.count + 1
}
);
}
render(){
return(
<div>
<h1>
{this.state.count}
</h1>
<button onClick={() => {this.count()}}>Increase Count</button>
</div>
);
}
}
export default Count;