Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ 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

Auto Save

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

              
                <ul class="descriptions">
  <li class="description" id="getInitialState">
    <h2 class="heading heading--2">getInitialState</h2>
    <p>Invoked once before the component is mounted. The return value will be used as the initial value of <code>this.state</code></p>
  </li>
  <li class="description" id="getDefaultProps">
    <h2 class="heading heading--2">getDefaultProps</h2>
    <p>Invoked once and cached when the class is created. Values in the mapping will be set on <code>this.props</code> if that prop is not specified by the parent component (i.e. using an in check).</p>

    <p>This method is invoked before any instances are created and thus cannot rely on <code>this.props</code>. In addition, be aware that any complex objects returned by <code>getDefaultProps()</code> will be shared across instances, not copied.</p>
  </li>
  <li class="description" id="componentWillMount">
    <h2 class="heading heading--2">componentWillMount</h2>
    <p>Invoked once, both on the client and server, immediately before the initial rendering occurs. If you call <code>setState</code> within this method, <code>render()</code> will see the updated state and will be executed only once despite the state change.</p>
  </li>
  <li class="description" id="render">
    <h2 class="heading heading--2">render</h2>
    <p>The render() method is required.</p>

    <p>When called, it should examine this.props and this.state and return a single child element. This child element can be either a virtual representation of a native DOM component (such as <code>&lt;div /&gt;</code> or <code>React.DOM.div()</code>) or another composite component that you've defined yourself.</p>

    <p>You can also return null or false to indicate that you don't want anything rendered. Behind the scenes, React renders a <code>&lt;noscript&gt;</code> tag to work with our current diffing algorithm. When returning null or false, <code>ReactDOM.findDOMNode(this)</code> will return <code>null</code>.</p>

    <p>The <code>render()</code> function should be pure, meaning that it does not modify component state, it returns the same result each time it's invoked, and it does not read from or write to the DOM or otherwise interact with the browser (e.g., by using <code>setTimeout</code>). If you need to interact with the browser, perform your work in <code>componentDidMount()</code> or the other lifecycle methods instead. Keeping <code>render()</code> pure makes server rendering more practical and makes components easier to think about.</p>
  </li>
  <li class="description" id="componentDidMount">
    <h2 class="heading heading--2">componentDidMount</h2>
    <p>Invoked once, only on the client (not on the server), immediately after the initial rendering occurs. At this point in the lifecycle, you can access any refs to your children (e.g., to access the underlying DOM representation). The <code>componentDidMount()</code> method of child components is invoked before that of parent components.</p>

    <p>If you want to integrate with other JavaScript frameworks, set timers using setTimeout or setInterval, or send AJAX requests, perform those operations in this method.</p>
  </li>
  <li class="description" id="componentWillReceiveProps">
    <h2 class="heading heading--2">componentWillReceiveProps</h2>
    <p>Invoked when a component is receiving new props. This method is not called for the initial render.</p>

    <p>Use this as an opportunity to react to a prop transition before <code>render()</code> is called by updating the state using <code>this.setState()</code>. The old props can be accessed via this.props. Calling <code>this.setState()</code> within this function will not trigger an additional render.</p>
  </li>
  <li class="description" id="shouldComponentUpdate">
    <h2 class="heading heading--2">shouldComponentUpdate</h2>
    <p>Invoked before rendering when new props or state are being received. This method is not called for the initial render or when <code>forceUpdate</code> is used.</p>

    <p>Use this as an opportunity to return <code>false</code> when you're certain that the transition to the new props and state will not require a component update.</p>
  </li>
  <li class="description" id="componentWillUpdate">
    <h2 class="heading heading--2">componentWillUpdate</h2>
    <p>Invoked immediately before rendering when new props or state are being received. This method is not called for the initial render.</p>

    <p>Use this as an opportunity to perform preparation before an update occurs.</p>
  </li>
  <li class="description" id="componentDidUpdate">
    <h2 class="heading heading--2">componentDidUpdate</h2>
    <p>Invoked immediately after the component's updates are flushed to the DOM. This method is not called for the initial render.</p>

    <p>Use this as an opportunity to operate on the DOM when the component has been updated.</p>
  </li>
  <li class="description" id="componentWillUnmount">
    <h2 class="heading heading--2">componentWillUnmount</h2>
    <p>Invoked immediately before a component is unmounted from the DOM.</p>

    <p>Perform any necessary cleanup in this method, such as invalidating timers or cleaning up any DOM elements that were created in <code>componentDidMount</code>.</p>
  </li>
  <li class="description description--placeholder">
    <h2 class="heading heading--2">React components lifecycle diagram</h2>
    <p>Click on a method to see a description.</p>
    <p>Taken from the <a href="https://facebook.github.io/react/docs/component-specs.html#lifecycle-methods">React documentation page</a>, compiled by <a href="https://eduardoboucas.com">Eduardo Bouças</a>.</p>
  </li>
  <li class="description__close"><a href="#">×</a></li>
</ul>

<div class="lanes">
  <ul class="lane">
    <li class="lane__title">Mounting</li>
    <li class="lane__item"><a class="step" href="#getInitialState">getInitialState</a></li>
    <li class="lane__item"><a class="step" href="#getDefaultProps">getDefaultProps</a></li>
    <li class="lane__item"><a class="step" href="#componentWillMount">componentWillMount</a></li>  
    <li class="lane__item"><a class="step" href="#render">render</a></li>
    <li class="lane__item"><a class="step" href="#componentDidMount">componentDidMount</a></li>  
  </ul>

  <ul class="lane">
    <li class="lane__title">Updating</li>
    <li class="lane__item"><a class="step" href="#componentWillReceiveProps">componentWillReceiveProps</a></li>
    <li class="lane__item"><a class="step" href="#shouldComponentUpdate">shouldComponentUpdate</a></li>
    <li class="lane__item"><a class="step" href="#componentWillUpdate">componentWillUpdate</a></li>  
    <li class="lane__item"><a class="step" href="#render">render</a></li>
    <li class="lane__item"><a class="step" href="#componentDidUpdate">componentDidUpdate</a></li>  
  </ul>

  <ul class="lane">
    <li class="lane__title">Unmounting</li>
    <li class="lane__item"><a class="step" href="#componentWillUnmount">componentWillUnmount</a></li>  
  </ul>
</div>
              
            
!

CSS

              
                $colour-accent: #61dafb;
$colour-background: #222;
$colour-background-shade-2: #2d2d2d;

p {
  margin-top: 20px;
  line-height: 1.6;
}

a {
  color: $colour-accent;
  text-decoration: none;
  
  &:hover {
    text-decoration: underline;
  }
}

code {
  background-color: $colour-background;
  font-family: Monaco, monospace;
  font-size: 0.9em;
  padding: 5px;
}

.logo {
  display: block;
  margin: 30px auto 0 auto;
  width: 100px;
  height: 100px;
}

.heading {
  margin-bottom: 0.5em;
}

.heading--2 {
  font-size: 30px;
}

.lanes {
  display: inline-block;
}

.lane {
  padding: 50px 0;
  text-align: left;
}

.lane + .lane {
  border-top: 1px solid white;
}

.lane__title {
  display: inline-block;
  color: white;
  margin-right: 10px;
  font-size: 12px;
  width: 80px;
  text-align: right;
}

.lane__item {
  display: inline-block;
  margin-right: -4px;
  
  & + & {
    &:before {
      content: '➞';
      color: white;
      font-size: 1em;
      vertical-align: middle;
      margin: 0 0.5em;
    }
  }
}

.step {
  display: inline-block;
  color: $colour-accent;
  text-decoration: none;
  font-size: 15px;
  border: 3px solid $colour-accent;
  border-radius: 10px;
  padding: 15px;
  transition: all 0.1s ease-out;
  
  &:hover {
    background-color: $colour-accent;
    color: black;
    text-decoration: none;
  }
}

.descriptions {
  position: relative;
  background-color: $colour-background-shade-2;
  color: white;
  padding: 20px;
  border-radius: 10px;
  min-height: 100px;
  max-width: 730px;
  margin: 40px auto;
}

.description {
  display: none;
  
  &:target,
  &--placeholder {
    display: block;
  }
  
  &:target ~ &--placeholder {
    display: none;
  }
  
  &:target ~ &__close {
    display: block;
  }
  
  &:not(.description--placeholder) {
    text-align: left;
  }
}

.description__close {
  position: absolute;
  top: 15px;
  right: 15px;
  font-size: 25px;
  transition: opacity 0.2s ease-out;
  display: none;
}

body {
  background-color: $colour-background;
  font-family: 'Montserrat', sans-serif;
  text-align: center;
}
              
            
!

JS

              
                
              
            
!
999px

Console