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

              
                <div id="root"></div>
              
            
!

CSS

              
                body {
  padding: 20px;
}

              
            
!

JS

              
                import React from "https://esm.sh/react@18.2.0";
import ReactDOM from "https://esm.sh/react-dom@18.2.0";

function List() {
    const [state, setState] = React.useState(false);
    const items = [
        { id: 1, label: "카테고리A" },
        { id: 2, label: "카테고리B" },
        { id: 3, label: "카테고리C" },
        { id: 4, label: "카테고리D" },
    ];

    const data = state ? items.reverse() : items;
    return (
        <div>
            <p>* 체크 박스를 클릭하고</p>
            <p>* 순서를 변경해서 어떻게 동작하는지 확인해 보세요. </p>
            <button onClick={() => setState(!state)} style={{ marginBottom: "10px" }}>
                순서 변경하기
            </button>
            <div style={{ display: "flex", gap: '30px' }}>
                <div>
                    <p style={{ fontWeight: 900, textDecoration: "underline" }}>
                        인덱스를 key로 사용할 경우
                    </p>
                    {data.map((item, i) => (
                        <Item key={i} item={item} />
                    ))}
                </div>
                <div>
                    <p style={{ fontWeight: 900, textDecoration: "underline" }}>
                        고유값을 key로 사용할 경우
                    </p>
                    {data.map((item) => (
                        <Item key={item.id} item={item} />
                    ))}
                </div>
            </div>
        </div>
    );
}

function Item({ item }) {
    return (
        <div>
            <input type="checkbox" onChange={() => {}} />
            {item.label}
        </div>
    );
}

function App() {
    return (
        <div>
            <List />
        </div>
    );
}

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

              
            
!
999px

Console