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/react/0.13.1/JSXTransformer.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.13.1/react-with-addons.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>
CSS
.green {
background-color: lightgreen;
}
.blue {
background-color: lightblue;
}
JavaScript 1.7
var Hello = React.createClass({
getInitialState: function(){
return {
color: 'blue'
};
},
handleClick: function(){
if (this.state.color === 'blue'){
this.setState({color: 'green'});
} else {
this.setState({color: 'blue'});
}
},
render: function() {
return (
<div>
<button className={this.state.color} onClick={this.handleClick}>My background is: {this.state.color}, Click me to change</button>;
<div>
)
}
});
React.render(<Hello name="World" />, document.getElementById('container'));