JSFiddle - React, Tailwind, and code Playground
HTML
<script src="http://fb.me/react-with-addons-0.11.0.js"></script>
<script src="http://fb.me/JSXTransformer-0.11.0.js"></script>
<script src="http://fb.me/react-js-fiddle-integration.js"></script>
JavaScript 1.7
var div = React.DOM.div,
p = React.DOM.p,
button = React.DOM.button;
var BottleGame = React.createClass({
getInitialState: function () {
return {
bottles: 99
};
},
render: function() {
var bottles = this.state.bottles,
text;
if (bottles > 1) {
text = bottles + ' bottles of beer on the wall';
} else if (bottles === 1) {
text = 'One bottle of beer on the wall';
} else {
text = 'No bottles of beer on the wall';
}
return div(
null,
p(null, text),
bottles > 0 ?
button({ onClick: this.handleTakeClick }, 'Take one down and pass it around') :
button({ onClick: this.handleAgainClick }, 'Start again')
);
},
handleTakeClick: function () {
this.setState({ bottles: this.state.bottles - 1 });
},
handleAgainClick: function () {
this.setState({ bottles: 99 });
}
});
React.renderComponent(BottleGame(), document.body);