Pen Settings

HTML

CSS

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

JavaScript

Babel includes JSX processing.

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

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

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.

HTML

              
                <div id="wrapper">
  <div class="container">
    <div class="row">
      <article class="col-md-12">
        <h1 class="text-center">Simple List in React</h1>
        <h2 class="text-center">Adding a dynamically generated list item</h2>
        <div id="app" class="app-container">

        </div>
      </article>
    </div>
  </div>
</div>
              
            
!

CSS

              
                
              
            
!

JS

              
                var App = React.createClass({
  getInitialState : function() {
    return (
      {
        fruits : {
          'fruit-1' : 'orange',
          'fruit-2' : 'apple'
        }
      }
     )
    },
    addFruit : function(fruit) {
     //create a unike key for each new fruit item
     var timestamp = (new Date()).getTime();
     // update the state object
     this.state.fruits['fruit-' + timestamp ] = fruit;
     // set the state
     this.setState({ fruits : this.state.fruits });
    },
    render: function() {
      return (
        <div className="component-wrapper">
          <FruitList fruits={this.state.fruits} />
          <AddFruitForm addFruit={this.addFruit} />
        </div>
      );
     }
    });

    var FruitList = React.createClass({
      render : function() {
        return (
          <div className="container">
            <ul className="list-group text-center">
              {
                Object.keys(this.props.fruits).map(function(key) {
                  return <li className="list-group-item list-group-item-info">{this.props.fruits[key]}</li>
                }.bind(this))
              }
            </ul>
           </div>
         );
       }
     });

    var AddFruitForm = React.createClass({
      createFruit : function(e) {
        e.preventDefault();
        //get the fruit object name from the form
        var fruit = this.refs.fruitName.value;
        //if we have a value
        //call the addFruit method of the App component
        //to change the state of the fruit list by adding an new item
        if(typeof fruit === 'string' && fruit.length > 0) {
          this.props.addFruit(fruit);
          //reset the form
          this.refs.fruitForm.reset();
        }
       },
       render : function() {
        return(
          <form className="form-inline" ref="fruitForm" onSubmit={this.createFruit}>
          <div className="form-group">
            <label for="fruitItem">
              Fruit Name
              <input type="text" id="fruitItem" placeholder="e.x.lemmon" ref="fruitName" className="form-control" />
            </label>
          </div>
          <button type="submit" className="btn btn-primary">Add Fruit</button>
         </form>
        )
       }
      });

      React.render(
        <App />,
        document.getElementById('app')
      );
              
            
!
999px

Console