React counter
React lessons
by Roman Ayapergenov
HTML
<script src="http://fb.me/react-with-addons-0.12.0.js"></script>
<script src="http://fb.me/JSXTransformer-0.12.0.js"></script>
<div id="container"></div>
<script src="http://fb.me/react-js-fiddle-integration.js"></script>
JavaScript 1.7
var Counter = React.createClass({
getInitialState: function() {
return {
count: 0
}
},
increment: function() {
this.setState({ count: this.state.count +1 });
},
render: function(){
return (
<div class="my-component">
<h1>Count:{this.state.count}</h1>
<button type="button" onClick={this.increment}>Increment</button>
</div>
);
}
});
React.render(
<Counter />,
document.getElementById("container")
);