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 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


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.


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.


                <h1>Probing the Mystery of React Component Identity</h1>
  <li>Enter a special request, and lock it.
  <li>Enter a name of "bob".
  <li>Note that the wrong thing is now locked.
  <li>Ponder the hidden dependencies of <code>useState</code>.
<div id="root"></div>
<h1>Possible Solutions?</h1>
  <li>Use <code>key</code>, even outside an array!
  <li>Never conditionally render a component. (like short-circuited operators, or <code>?:</code>)
  <li>Use the visible attribute instead?
  <li>Always use a key for component arrays.  React is good at reminding you to do this.



                body {
  background: #223;
  color: #eee;


                // What is the identity of the scope for useState?
// I know about invocation order, but there's obviously something else.
// Answer:
// Among siblings, the identity appears loosely to be the tuple (factory, key ?? index)
//    Factory refers to the function or class that defines the component.
//    Key refers to the key attribute
//    Index refers to the document order as rendered

const { useState } = React;

function LabeledInput({ label, value, onValueChange }) {
    const [locked, setLocked] = useState(false);
    return <p>
            <input disabled={locked} value={value} onChange={e=>onValueChange(} />
            <input type="checkbox" checked={locked} onChange={e=>setLocked(} />
            Lock input

function Form() {
    const [name, setName] = useState("");
    const [confirmation, setConfirmation] = useState("");
    const [request, setRequest] = useState("");

    const nameInput = <LabeledInput label="Name" value={name} onValueChange={setName} />;
    const confirmationInput = <LabeledInput label="Indicate your confirmation, BOB" value={confirmation} onValueChange={setConfirmation} />;
    const requestInput = <LabeledInput label="Special Request" value={request} onValueChange={setRequest} />;

    const isBob = name.toLowerCase() === "bob";
    return(isBob // bob is always screwing everything up
        ? <fieldset>
            <legend>Special Bob Form</legend>
            You better not mess up this time BOB.
        : <fieldset>
            <legend>Standard Form</legend>

ReactDOM.render(<Form />, document.getElementById('root'));