Skip to content

Instantly share code, notes, and snippets.

@LeeCheneler
Created August 24, 2018 09:51
Show Gist options
  • Save LeeCheneler/ea8ed15df615da9ec73096a0b630f6ab to your computer and use it in GitHub Desktop.
Save LeeCheneler/ea8ed15df615da9ec73096a0b630f6ab to your computer and use it in GitHub Desktop.
Example counter react component
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