Created
January 11, 2017 18:38
-
-
Save panduroab/c137a3b81cb7833743002e7c22e0f594 to your computer and use it in GitHub Desktop.
This file contains hidden or 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'; | |
| class Display extends Component { | |
| render() { | |
| return <div>{this.props.number}</div>; | |
| } | |
| } | |
| class App extends Component { | |
| constructor() { | |
| super(); | |
| this.state = { number: 0 }; | |
| } | |
| _increment = () => { | |
| this.setState(prevState => ({ | |
| number: prevState.number + 1 | |
| })); | |
| } | |
| _decrement = () => { | |
| this.setState(prevState => ({ | |
| number: prevState.number - 1 | |
| })); | |
| } | |
| render() { | |
| return ( | |
| <div> | |
| <h3>Main Container</h3> | |
| <Display number={this.state.number} /> | |
| <button onClick={this._increment}>Increment</button> | |
| <button onClick={this._decrement}>Decrement</button> | |
| </div> | |
| ); | |
| } | |
| } | |
| export default App; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment