Created
August 2, 2016 03:12
-
-
Save dsdemaria/a541ae40d5e185402cfddf9702bbb118 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'; | |
export default class App extends Component { | |
render() { | |
return ( | |
<div className='container'> | |
<Counter increment={1} /> | |
<Counter increment={5} /> | |
<Counter increment={15} /> | |
<Counter increment={25} /> | |
</div> | |
); | |
} | |
} | |
class Counter extends Component { | |
constructor(props) { | |
super(props); | |
this.state = { | |
count: 0, | |
}; | |
} | |
render() { | |
return ( | |
<div> | |
<input | |
value={this.state.count} | |
/> | |
<button | |
onClick={() => { | |
this.setState({ | |
count: this.state.count + this.props.increment, | |
}); | |
}}>Increment by {this.props.increment}! | |
</button> | |
</div> | |
); | |
} | |
} | |
Counter.propTypes = { | |
increment: React.PropTypes.number.isRequired, | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment