Last active
August 7, 2017 05:10
-
-
Save mariusandra/997d5085ebd23bc2b6b6b3f66c3759ec to your computer and use it in GitHub Desktop.
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, { Component } from 'react' | |
export default class Counter extends Component { | |
constructor (props) { | |
this.state = { | |
counter: 0 | |
} | |
} | |
handleIncrement = (amount) => { | |
const { counter } = this.state | |
this.setState({ counter: counter + amount }) | |
} | |
handleDecrement = (amount) => { | |
const { counter } = this.state | |
this.setState({ counter: counter - amount }) | |
} | |
render () { | |
const { counter } = this.state | |
return ( | |
<div> | |
<p>Count: {counter}</p> | |
<button onClick={() => this.handleIncrement(1)}>Increment</button> | |
<button onClick={() => this.handleDecrement(1)}>Decrement</button> | |
</div> | |
) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment