Skip to content

Instantly share code, notes, and snippets.

@rafaellucio
Last active December 3, 2017 22:02
Show Gist options
  • Save rafaellucio/5c815de0e44f9cbd6c604f36f34cbd6b to your computer and use it in GitHub Desktop.
Save rafaellucio/5c815de0e44f9cbd6c604f36f34cbd6b to your computer and use it in GitHub Desktop.
import React, { Component } from 'react'
export default class Counter extends Component {
state = {
count: 0
}
increment = () => {
this.setState({
count: this.state.count + 1
})
}
decrement = () => {
this.setState({
count: this.state.count - 1
})
}
render() {
return (
<div>
<h2>Counter</h2>
<div>
<button onClick={this.decrement}>-</button>
<span>{this.state.count}</span>
<button onClick={this.increment}>+</button>
</div>
</div>
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment