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">
<!-- This element's contents will be replaced with your component. -->
</div>
JavaScript 1.7
var FormattedMessage = React.createClass({
render: function() {
return <span>{this.props.defaultMessage || this.props.id}</span>
}
});
var Hello = React.createClass({
getInitialState: function () {
return {
activeIndex: 0
};
},
_updateState: function () {
this.setState({activeIndex: 1});
},
render: function() {
var title;
this.props.children.map(function(test, index) {
if (index === this.state.activeIndex) {
title = test.props.title;
}
}.bind(this));
return (
<div aria-labelledby="content_description">
<title id="content_description">
<FormattedMessage id="Tab" defaultMessage={title + 'Tab'} />
</title>
Hello {title}
<br/>
<button onClick={this._updateState}>Update State</button>
</div>
);
}
});
ReactDOM.render(
<Hello>
<div title="world"></div>
<div title="world2"></div>
</Hello>,
document.getElementById('container')
);