Last active
July 8, 2018 19:16
-
-
Save balazimichal/52b22128c4b65a1d5f7a2db25645dff8 to your computer and use it in GitHub Desktop.
react-simple-count
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'; | |
import './App.css'; | |
class App extends Component { | |
constructor(props) { | |
super(props) | |
this.addCount = this.addCount.bind(this) | |
this.deductCount = this.deductCount.bind(this) | |
} | |
state = { | |
count: 0 | |
} | |
addCount() { | |
this.setState((prevState) => ({ | |
count: prevState.count + 1 | |
})) | |
} | |
deductCount() { | |
this.setState((prevState) => ({ | |
count: prevState.count - 1 | |
})) | |
} | |
render() { | |
return ( | |
<div> | |
{JSON.stringify(this.state)} | |
<h1>{this.state.count}</h1> | |
<button onClick={this.addCount}>+1</button> | |
<button onClick={this.deductCount}>-1</button> | |
</div> | |
); | |
} | |
} | |
export default App; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment