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>
React
var Container = React.createClass({
onClicked: function() {
console.log('Container.onClicked fido');
if(this.state.isShowing){
this.refs.myHelloWorld.hide();
} else {
this.setState({ isShowing: true });
}
},
onAnimationComplete: function() {
console.log('Container.onAnimationComplete');
this.setState({ isShowing: false });
},
getInitialState: function() {
return { isShowing: false };
},
render: function() {
var helloWorld = this.state.isShowing ? <Hello name="World!" onComplete={this.onAnimationComplete} ref="myHelloWorld" /> : '';
return (
<div id="container">
<MyButton onButtonClicked={this.onClicked}/>
{helloWorld}
</div>
);
}
});
var MyButton = React.createClass({
render: function() {
return <button onClick={this.props.onButtonClicked}>Toggle</button>;
}
});
var Hello = React.createClass({
hide: function() {
console.log('Hello.hide');
var that = this;
$(React.findDOMNode(this)).stop(true).fadeOut({
duration: 1200,
complete: function() {
that.props.onComplete();
}
});
},
componentDidMount: function() {
console.log('Hello.componentDidMount');
$(React.findDOMNode(this)).stop(true).hide().fadeIn(3000);
},
componentWillUnmount: function() {
console.log('Hello.componentWillUnmount');
},
render: function() {
return <div>Hello toko fidele{ this.props.name }</div>;
}
});
React.render(<Container />, document.body);