React Base Fiddle (JSX)

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

by Fareez Ahmed

HTML

<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.14.0/react-with-addons.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.13.1/JSXTransformer.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.14.0/react-dom.min.js"></script>
<script src="https://facebook.github.io/react/js/jsfiddle-integration.js"></script>

<div id="container">
    <!-- This element's contents will be replaced with your component. -->
</div>

JavaScript 1.7

var Liquid = React.createClass({
    getInitialState: function() {
        return {
            currentTemp: 10
        };
    },

    setTemperature: function(e) {
        this.setState({ currentTemp: e.target.value });
    },

    render: function() {
    	// empty variable that will hold either "Liquid", "Solid", or "Gas"
        var stateOfMatter;
        
        // If temp is on/below freezing, it's a solid 
        if (this.state.currentTemp <= this.props.config.freezing) {
            stateOfMatter = 'Solid';
            
        // if temp is on/above boiling, it's a gas
        } else if (this.state.currentTemp >= this.props.config.boiling) {
            stateOfMatter = 'Gas';
            
        // otherwise it's just a liquid
        } else {
            stateOfMatter = 'Liquid';
        }
        
        
        return (
        	<div>
            	<input type="text" onChange={ this.setTemperature } value={ this.state.currentTemp } />
            	<p>At { this.state.currentTemp }°F, { this.props.config.name } is considered to be a "{ stateOfMatter }" state of matter.</p>
        	</div>
        );
        
    }
});

var LiquidsList = React.createClass({
    render: function() {
    	var liquids = this.props.liquids.map(function(liquidObject, index){
                        return <Liquid config={ liquidObject } key={ index } />;
                      })
        return (
        	<div>
            	{ liquids }
        	</div>
        );
        
    }
});
 

// Create object to hold water's name, freezing & boiling points
var water = {
    name: "Water",
    freezing: 32,
    boiling: 212
};

// Create object to hold ethanol's name, freezing & boiling points
var ethanol = {
    name: "Ethanol",
    freezing: -173.2,
    boiling: 173.1
};
// Render our LiquidsList component!
ReactDOM.render(<LiquidsList liquids={ [ethanol, water] } />, document.getElementById('container'));