React Base Fiddle (JSX)
Starting point for creating JSFiddles with React. This uses React with Addons.
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.24/browser.js"></script>
<script src="https://fb.me/react-with-addons-0.14.0.js"></script>
<script src="https://fb.me/react-dom-0.14.0.js"></script>
<script src="https://facebook.github.io/react/js/jsfiddle-integration-babel.js"></script>
<div id="container">
</div>
JavaScript 1.7
var Example = React.createClass({
getInitialState: function() {
return {
showCounter: false,
counter: 0
};
},
tick: function() {
this.setState({ counter: this.state.counter + 1 });
},
componentDidMount: function() {
this.interval = setInterval(this.tick, 1000);
},
componentWillUnmount: function() {
clearInterval(this.interval);
},
render: function() {
console.log('render');
return <div>{this.state.showCounter ? this.state.counter : 'counter is hidden'}</div>;
}
});
ReactDOM.render(
<Example />,
document.getElementById('container')
);