React Base Fiddle (JSX)
Starting point for creating JSFiddles with React. This uses React with Addons.
by xufocoder
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.24/browser.js"></script>
<script src="https://npmcdn.com/react@latest/dist/react-with-addons.js"></script>
<script src="https://npmcdn.com/react-dom@latest/dist/react-dom.js"></script>
<script src="https://facebook.github.io/react/js/jsfiddle-integration-babel.js"></script>
<div id="reactContainerElement"></div>
JavaScript 1.7
class Parent extends React.Component {
constructor() {
super();
this.handleClick = this.handleClick.bind(this);
}
handleClick() {
this.refs.childRef.makeRed();
}
render() {
return (
<div>
<button onClick={this.handleClick}>Make it red</button>
<Child ref='childRef' />
</div>
);
}
}
class Child extends React.Component {
constructor() {
super();
this.state = {
color: 'greed'
}
}
makeRed() {
this.setState({
color: 'red'
})
}
render() {
return (
<div>My color is {this.state.color}</div>
);
}
}
ReactDOM.render(
<Parent />,
document.getElementById('reactContainerElement')
);