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.6.js"></script>
<script src="https://fb.me/react-dom-0.14.6.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.1.8/semantic.min.css">
<script src="https://code.jquery.com/jquery-2.2.2.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.1.8/semantic.min.js"></script>
<script src="https://facebook.github.io/react/js/jsfiddle-integration-babel.js"></script>
<div id="app">
<!-- This element's contents will be replaced with your component. -->
</div>
CSS
#app {
margin: 10px;
}
#card{
margin-top: 10px;
}
JavaScript 1.7
class App extends React.Component {
constructor(props){
super(props);
this.state = {
number: 0,
show: false
}
}
_increase(){
this.setState({
number: this.state.number+1
});
}
_show() {
this.setState({
show: true
});
}
_unmount() {
this.setState({
number: 0,
show: false
});
}
render(){
let component = (<Card number={this.state.number}/>);
return (
<div>
<Button caption="Show Card" customClass="green" onClick={this._show.bind(this)} />
<Button caption="Increase Number" customClass="blue" onClick={this._increase.bind(this)}/>
<Button caption="Unmount Card" customClass="red" onClick={this._unmount.bind(this)}/>
{this.state.show ? component : ""}
</div>
);
}
}
class Button extends React.Component {
render() {
let className = "ui button " + this.props.customClass;
return (
<div onClick={this.props.onClick}className={className}>{this.props.caption}</div>
)
}
}
class Card extends React.Component {
constructor(props){
super(props);
console.log("constructor");
}
componentWillMount(){
console.log("componentWillMount");
}
componentDidMount(){
console.log("componentDidMount");
}
componentWillReceiveProps(nextProps){
console.log("componentWillReceiveProps: " + JSON.stringify(nextProps));
}
shouldComponentUpdate(nextProps, nextState){
console.log("shouldComponentUpdate: " + JSON.stringify(nextProps) + " " + JSON.stringify(nextState));
return true;
}
componentWillUpdate(nextProps, nextState){
console.log("componentWillUpdate: " + JSON.stringify(nextProps) + " " +...