Created
June 20, 2016 21:32
-
-
Save osmelmora/436917ea0d08b8ea97281b07a84248ca 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
var Component = React.createClass({ | |
getDefaultProps: function() { | |
console.log('getDefaultProps'); | |
return { | |
title: "Basic counter!!!", | |
step: 1 | |
} | |
}, | |
getInitialState: function() { | |
console.log('getInitialState'); | |
return { | |
count: (this.props.initialCount || 0) | |
}; | |
}, | |
render: function() { | |
console.log('render'); | |
var step = this.props.step; | |
return ( | |
<div> | |
<h1>{this.props.title}</h1> | |
<div>{this.state.count}</div> | |
<input type='button' value='+' onClick={this.updateCounter.bind(this, step)} /> | |
<input type='button' value='-' onClick={this.updateCounter.bind(this, -step)} /> | |
</div> | |
); | |
}, | |
updateCounter: function(value) { | |
var newCount = this.state.count + value; | |
this.setState({count: newCount}); | |
}, | |
propTypes: { | |
title: React.PropTypes.string, | |
initialCount: React.PropTypes.number, | |
step: React.PropTypes.number | |
} | |
}); | |
ReactDOM.render( | |
React.createElement(Component, {initialCount: 5, step: 2}), | |
document.getElementById('app-container') | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment