Created
August 24, 2018 09:51
-
-
Save LeeCheneler/ea8ed15df615da9ec73096a0b630f6ab to your computer and use it in GitHub Desktop.
Example counter react component
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 Counter extends React.Component { | |
state = { | |
count: 0 | |
} | |
onClick = () => { | |
this.setState(prevState => ({ ...prevState, count: prevState.count + 1 })) | |
} | |
render = () => ( | |
<div> | |
<button type="button" onClick={this.onClick}> | |
Increment | |
</button> | |
<span>Clicked: {this.state.count}</span> | |
</div> | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment