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="root"></div>
              
            
!

CSS

              
                
              
            
!

JS

              
                class App extends React.Component {
  state = {
    restoreIssue: {
      border: '1px solid green',
      borderColor: 'red'
    },
    orderIssue: {
      border: '1px solid green',
      borderColor: 'red'
    }
  }

  componentDidMount() {
    this.setState({
      restoreIssue: {
        border: '1px solid green'
      },
      orderIssue: {
        border: '1px solid blue',
      }
    })
  }

  render() {
    return (
      <React.Fragment>
        <h1>React inline styles issues</h1>
        <p>Due to the way how the DOM updates inline styles (node.style) using shorthand properties in inline styles can lead to the two issues below. Note that this is not React's fault since you'd get the same behavior in vanilla js if you were to update the style attribute by hand.</p>
        <div style={this.state.restoreIssue}>
          <h2>Restore one of the shorthand values</h2>
          In this test we set:
          <CodeBlock>
            {`{
              border: '1px solid green',
              borderColor: 'red'
           }`}
          </CodeBlock>

          and on `componentDidMout` reset the style property to:
          <CodeBlock>
            {`{
              border: '1px solid green'
           }`}
          </CodeBlock>

          We expect the border of this container to be `green` but instead it should be `black` (or rather `currentColor`);
        What happens is that when we update the styles React sets
        <CodeBlock>
            node.style.borderColor = ''
        </CodeBlock>

          Since the value for `border` hasn't changed React doesn't reset it.
          At this point the DOM doesn't know what was the previous value of `borderColor` and there you go you have your bug!
        </div>
        <div style={this.state.orderIssue}>
          <h2>Resetting a shorthand overrides the long form value</h2>

          Like in the previous test, we set:

          <CodeBlock>
            {`{
              border: '1px solid green',
              borderColor: 'red'
           }`}
          </CodeBlock>

          and on `componentDidMout` reset the style property to:
          <CodeBlock>
            {`{
              border: '1px solid blue'
           }`}
          </CodeBlock>

          We would expect React to reconcile this as follow:
          <CodeBlock>
            {`{
              border: '1px solid blue',
              borderColor: 'red'
           }`}
          </CodeBlock>

          and getting a `red` border but instead it is `blue`.
          This is due to the fact that when you set a short hand value again,
          it overrides all the long form ones:
          <CodeBlock>
            {`node.style.border = '1px solid green'
            node.style.borderColor: 'red'
            node.style.border = '1px solid blue'`}
          </CodeBlock>

        </div>
      </React.Fragment>
    )
  }
}

ReactDOM.render(<App />, document.getElementById("root"));


function CodeBlock({ children }) {
  return <code style={{ margin: '1em 0', whiteSpace: 'pre-line', display: 'block' }}>{children}</code>
}
              
            
!
999px

Console