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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation


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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

              <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 this.props.weather:', this.props.weather, 'new props is nextProps.weahter:' + nextProps.weather);
        //组件判断是否重新渲染时调用 Skips render() if returns false
        shouldComponentUpdate: function (nextProps, nextState) {
            console.log('-------shouldComponentUpdate execute-------')
            var flag = true;
//            if (nextProps.weather == '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:', this.props.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: {this.props.weather}</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('http://api.openweathermap.org/data/2.5/weather?q=' + cityName , function (data,status) {
                    if (status === 'success') {
                        var weather = data.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
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.