Created
January 11, 2019 01:23
-
-
Save Anirudhk94/c3fd5d939f2f03e345bfabab50348010 to your computer and use it in GitHub Desktop.
[React] Increment Button Label On Click
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
class Button extends React.Component { | |
state = {counter : 0}; | |
changeLabel = () => { | |
this.setState({ | |
counter: this.state.counter + 1 | |
}) | |
} | |
render() { | |
return( | |
<button onClick={this.changeLabel}> | |
{this.state.counter} | |
</button> | |
) | |
} | |
} | |
ReactDOM.render(<Button />, mountNode) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment