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