React Base Fiddle (JSX)

Starting point for creating JSFiddles with React. This uses React with Addons.

by Cody Lindley

HTML

<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>
<div id="app"></div>

Babel + JSX

var Timer = React.createClass({
    render: function() {
	  return (
  		<div>{this.props.now}</div>
		)
	}
});

var App = React.createClass({
  getInitialState: function() {
    return {now: Date.now()};
  },

  componentDidMount: function() {
	var foo = setInterval(function() {
		this.setState({now: Date.now()});
	}.bind(this), 1000);

	setTimeout(function(){ clearInterval(foo); }, 5000);
	//DON'T DO THIS, JUST DEMONSTRATING .forceUpdate() 
	setTimeout(function(){ this.state.now = 'foo'; this.forceUpdate() }.bind(this), 10000);
  },
  
  render: function() {
	  return (
  		<Timer now={this.state.now}></Timer>
		)
	}
});

ReactDOM.render(< App / >, app);