Pen Settings



CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource


Babel is required to process package imports. If you need a different preprocessor remove all packages first.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource


Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.


                <div id="content" style="margin-bottom: 20px;"></div>




                /** @jsx React.DOM */
var ComponentBox = React.createClass({
        getInitialState: function () {
            console.log('-------getInitalState execute-------');
            return {
               stateValue: 'zhangmeng'
        getDefaultProps: function () {
            console.log('-------getDefaultProps execute-------')
            return {
                propValue: 'beijing',
                weather: ''
        /**** 生命周期方法 mounting update render Unmounting*****/
        componentWillMount: function () {
            console.log('-------componentWillMount execute-------','propValue:' + this.props.propValue, 'stateValue:' + this.state.stateValue)
//            this.setState({
//                stateValue: 'jiangyu'//render前会执行,改变初始值但是不会触发额外的render
//            })
        //什么时候会被调用 已加载组件收到新的参数时调用 Use setState() here 例子??
        componentWillReceiveProps: function (nextProps) {
            console.log('-------componentWillReceiveProps execute-------', 'old weather is',, 'new props is nextProps.weahter:' +;
        //组件判断是否重新渲染时调用 Skips render() if returns false
        shouldComponentUpdate: function (nextProps, nextState) {
            console.log('-------shouldComponentUpdate execute-------')
            var flag = true;
//            if ( == 'light rain' ) {
//                flag = false;
//            }
            return flag;
        componentWillUpdate: function (nextProps, nextState) {
            console.log('-------componentWillUpdate execute-------');
        render: function () {
            console.log('-------render execute-------', 'propValue:' + this.props.propValue, 'weather:',, 'stateValue:' + this.state.stateValue);
            return (<div>
                      <input type="text" ref="myTextInput" defaultValue={this.props.propValue} />
                      <input type="button" ref="myButton" value="提交"/>
                      <div>propValue is: {this.props.propValue}</div>
                      <div>ajaxResult is: {}</div>
        //Operate on the DOM here
        componentDidUpdate: function (prevProps, prevState) {
            console.log('-------componentDidUpdate execute-------')
        componentDidMount: function () {
            console.log('-------componentDidMount execute-------')
            var input = $('input[type="text"]');
            var cityName = this.props.propValue;
            $.get('' + cityName , function (data,status) {
                    if (status === 'success') {
                        var weather = || [];
                        if (weather.length && weather[0]) {
                            console.log('**** props weather changed *****');
                                weather: weather[0].description

        //Invoked before DOM removal
        componentWillUnmount: function () {
            console.log('-------componentWillUnmount execute-------')
    var compInstance = React.render(
            <ComponentBox />,
            document.getElementById('content') //DOM Element