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>
);
}
});
// Create object to hold water's name, freezing & boiling points
var water = {
name: "Water",
freezing: 32,
boiling: 212
};
// Create a div for water powered Liquid component and put it in the container div
var waterEl = document.createElement("div");
document.getElementById('container').appendChild(waterEl);
// Render our Liquid component with water's properties!
ReactDOM.render(<Liquid config={ water } />, waterEl);
// Create object to hold ethanol's name, freezing & boiling points
var ethanol = {
name: "Ethanol",
freezing: -173.2,
boiling: 173.1
};
// Create a div for our ethanol powered Liquid component and put it in the container div
var ethanolEl = document.createElement("div");
document.getElementById('container').appendChild(ethanolEl);
// Render our Liquid component with ethanol's...