Last active
April 4, 2021 17:00
-
-
Save myogeshchavan97/38c0ad6b022082a8ba1fcbcd6ef3f24c to your computer and use it in GitHub Desktop.
Class Based Counter Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import ReactDOM from 'react-dom'; | |
class App extends React.Component { | |
state = { | |
counter: 0 | |
}; | |
handleOnClick = () => { | |
this.setState(prevState => ({ | |
counter: prevState.counter + 1 | |
})); | |
}; | |
render() { | |
return ( | |
<div> | |
<p>Counter value is: {this.state.counter} </p> | |
<button onClick={this.handleOnClick}>Increment</button> | |
</div> | |
); | |
} | |
} | |
ReactDOM.render(<App />, document.getElementById('root')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment