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

CSS

              
                body {
  font-family: sans-serif;
}

.property {
  color: steelblue;
  margin-left: 10px;
}

button {
  width: 30px;
  height: 30px;
  font-size: 24px;
}

li {
  list-style-type: none;
}

h3 {
  margin-left: 50px;
}
              
            
!

JS

              
                // useState is a React method that lets us work with state data
const useState = React.useState

// Data created from https://mockaroo.com/
const tshirts = [{
  "id": 1,
  "name": "nibh",
  "color": "Indigo",
  "gender": "Male",
  "size": "M",
  "price": 394,
  "tax": 25,
  "shipping_cost": 53
}, {
  "id": 2,
  "name": "risus",
  "color": "Khaki",
  "gender": "Male",
  "size": "S",
  "price": 486,
  "tax": 25,
  "shipping_cost": 46
}, {
  "id": 3,
  "name": "nec sem duis",
  "color": "Green",
  "gender": "Male",
  "size": "3XL",
  "price": 443,
  "tax": 25,
  "shipping_cost": 45
}, {
  "id": 4,
  "name": "nunc",
  "color": "Turquoise",
  "gender": "Female",
  "size": "M",
  "price": 404,
  "tax": 25,
  "shipping_cost": 49
}, {
  "id": 5,
  "name": "semper sapien a",
  "color": "Aquamarine",
  "gender": "Female",
  "size": "XL",
  "price": 374,
  "tax": 25,
  "shipping_cost": 52
}, {
  "id": 6,
  "name": "duis",
  "color": "Aquamarine",
  "gender": "Male",
  "size": "L",
  "price": 471,
  "tax": 25,
  "shipping_cost": 40
}, {
  "id": 7,
  "name": "tortor id nulla",
  "color": "Mauv",
  "gender": "Female",
  "size": "2XL",
  "price": 495,
  "tax": 25,
  "shipping_cost": 52
}, {
  "id": 8,
  "name": "in",
  "color": "Violet",
  "gender": "Female",
  "size": "L",
  "price": 417,
  "tax": 25,
  "shipping_cost": 70
}, {
  "id": 9,
  "name": "pede",
  "color": "Crimson",
  "gender": "Male",
  "size": "3XL",
  "price": 435,
  "tax": 25,
  "shipping_cost": 58
}, {
  "id": 10,
  "name": "eget congue",
  "color": "Goldenrod",
  "gender": "Female",
  "size": "L",
  "price": 369,
  "tax": 25,
  "shipping_cost": 43
}, {
  "id": 11,
  "name": "justo morbi",
  "color": "Maroon",
  "gender": "Female",
  "size": "M",
  "price": 325,
  "tax": 25,
  "shipping_cost": 65
}, {
  "id": 12,
  "name": "purus phasellus in",
  "color": "Blue",
  "gender": "Female",
  "size": "2XL",
  "price": 354,
  "tax": 25,
  "shipping_cost": 69
}, {
  "id": 13,
  "name": "porttitor lacus at",
  "color": "Blue",
  "gender": "Female",
  "size": "2XL",
  "price": 488,
  "tax": 25,
  "shipping_cost": 50
}, {
  "id": 14,
  "name": "nullam",
  "color": "Teal",
  "gender": "Female",
  "size": "S",
  "price": 387,
  "tax": 25,
  "shipping_cost": 51
}, {
  "id": 15,
  "name": "tempus sit",
  "color": "Puce",
  "gender": "Female",
  "size": "2XL",
  "price": 486,
  "tax": 25,
  "shipping_cost": 74
}, {
  "id": 16,
  "name": "blandit",
  "color": "Violet",
  "gender": "Male",
  "size": "S",
  "price": 450,
  "tax": 25,
  "shipping_cost": 48
}, {
  "id": 17,
  "name": "id",
  "color": "Puce",
  "gender": "Male",
  "size": "S",
  "price": 331,
  "tax": 25,
  "shipping_cost": 50
}, {
  "id": 18,
  "name": "augue",
  "color": "Mauv",
  "gender": "Female",
  "size": "2XL",
  "price": 402,
  "tax": 25,
  "shipping_cost": 58
}, {
  "id": 19,
  "name": "et",
  "color": "Maroon",
  "gender": "Female",
  "size": "S",
  "price": 426,
  "tax": 25,
  "shipping_cost": 40
}, {
  "id": 20,
  "name": "in hac",
  "color": "Indigo",
  "gender": "Female",
  "size": "L",
  "price": 308,
  "tax": 25,
  "shipping_cost": 57
}, {
  "id": 21,
  "name": "praesent blandit",
  "color": "Goldenrod",
  "gender": "Male",
  "size": "3XL",
  "price": 369,
  "tax": 25,
  "shipping_cost": 58
}, {
  "id": 22,
  "name": "amet eleifend",
  "color": "Turquoise",
  "gender": "Male",
  "size": "L",
  "price": 307,
  "tax": 25,
  "shipping_cost": 45
}, {
  "id": 23,
  "name": "curae nulla dapibus",
  "color": "Khaki",
  "gender": "Female",
  "size": "M",
  "price": 338,
  "tax": 25,
  "shipping_cost": 57
}, {
  "id": 24,
  "name": "non velit nec",
  "color": "Mauv",
  "gender": "Female",
  "size": "M",
  "price": 373,
  "tax": 25,
  "shipping_cost": 70
}, {
  "id": 25,
  "name": "elementum",
  "color": "Blue",
  "gender": "Female",
  "size": "L",
  "price": 327,
  "tax": 25,
  "shipping_cost": 57
}, {
  "id": 26,
  "name": "nulla sed vel",
  "color": "Maroon",
  "gender": "Female",
  "size": "2XL",
  "price": 365,
  "tax": 25,
  "shipping_cost": 68
}, {
  "id": 27,
  "name": "diam erat fermentum",
  "color": "Green",
  "gender": "Male",
  "size": "L",
  "price": 437,
  "tax": 25,
  "shipping_cost": 54
}, {
  "id": 28,
  "name": "augue vestibulum rutrum",
  "color": "Pink",
  "gender": "Male",
  "size": "L",
  "price": 444,
  "tax": 25,
  "shipping_cost": 75
}, {
  "id": 29,
  "name": "hendrerit",
  "color": "Pink",
  "gender": "Male",
  "size": "XL",
  "price": 417,
  "tax": 25,
  "shipping_cost": 61
}, {
  "id": 30,
  "name": "integer tincidunt ante",
  "color": "Blue",
  "gender": "Female",
  "size": "XL",
  "price": 402,
  "tax": 25,
  "shipping_cost": 49
}, {
  "id": 31,
  "name": "posuere cubilia curae",
  "color": "Pink",
  "gender": "Male",
  "size": "L",
  "price": 498,
  "tax": 25,
  "shipping_cost": 48
}, {
  "id": 32,
  "name": "amet",
  "color": "Goldenrod",
  "gender": "Male",
  "size": "S",
  "price": 475,
  "tax": 25,
  "shipping_cost": 55
}, {
  "id": 33,
  "name": "et",
  "color": "Turquoise",
  "gender": "Female",
  "size": "S",
  "price": 456,
  "tax": 25,
  "shipping_cost": 65
}, {
  "id": 34,
  "name": "eget tempus",
  "color": "Indigo",
  "gender": "Female",
  "size": "XS",
  "price": 442,
  "tax": 25,
  "shipping_cost": 53
}, {
  "id": 35,
  "name": "in",
  "color": "Indigo",
  "gender": "Female",
  "size": "L",
  "price": 351,
  "tax": 25,
  "shipping_cost": 56
}, {
  "id": 36,
  "name": "mauris enim",
  "color": "Goldenrod",
  "gender": "Female",
  "size": "2XL",
  "price": 385,
  "tax": 25,
  "shipping_cost": 71
}, {
  "id": 37,
  "name": "pede lobortis",
  "color": "Aquamarine",
  "gender": "Female",
  "size": "2XL",
  "price": 337,
  "tax": 25,
  "shipping_cost": 70
}, {
  "id": 38,
  "name": "eget massa tempor",
  "color": "Turquoise",
  "gender": "Male",
  "size": "L",
  "price": 340,
  "tax": 25,
  "shipping_cost": 40
}, {
  "id": 39,
  "name": "tincidunt eget",
  "color": "Fuscia",
  "gender": "Male",
  "size": "2XL",
  "price": 389,
  "tax": 25,
  "shipping_cost": 56
}, {
  "id": 40,
  "name": "eu",
  "color": "Mauv",
  "gender": "Female",
  "size": "L",
  "price": 360,
  "tax": 25,
  "shipping_cost": 47
}, {
  "id": 41,
  "name": "tortor",
  "color": "Fuscia",
  "gender": "Female",
  "size": "3XL",
  "price": 430,
  "tax": 25,
  "shipping_cost": 40
}, {
  "id": 42,
  "name": "tellus nisi eu",
  "color": "Teal",
  "gender": "Female",
  "size": "M",
  "price": 445,
  "tax": 25,
  "shipping_cost": 48
}, {
  "id": 43,
  "name": "tellus",
  "color": "Turquoise",
  "gender": "Female",
  "size": "3XL",
  "price": 487,
  "tax": 25,
  "shipping_cost": 65
}, {
  "id": 44,
  "name": "nam ultrices libero",
  "color": "Yellow",
  "gender": "Female",
  "size": "2XL",
  "price": 463,
  "tax": 25,
  "shipping_cost": 50
}, {
  "id": 45,
  "name": "aliquet",
  "color": "Violet",
  "gender": "Male",
  "size": "2XL",
  "price": 443,
  "tax": 25,
  "shipping_cost": 42
}, {
  "id": 46,
  "name": "aenean lectus",
  "color": "Indigo",
  "gender": "Male",
  "size": "3XL",
  "price": 396,
  "tax": 25,
  "shipping_cost": 44
}, {
  "id": 47,
  "name": "rutrum",
  "color": "Blue",
  "gender": "Male",
  "size": "S",
  "price": 439,
  "tax": 25,
  "shipping_cost": 49
}, {
  "id": 48,
  "name": "non quam",
  "color": "Puce",
  "gender": "Male",
  "size": "S",
  "price": 313,
  "tax": 25,
  "shipping_cost": 54
}, {
  "id": 49,
  "name": "vitae",
  "color": "Orange",
  "gender": "Male",
  "size": "XL",
  "price": 496,
  "tax": 25,
  "shipping_cost": 59
}, {
  "id": 50,
  "name": "a nibh",
  "color": "Puce",
  "gender": "Female",
  "size": "3XL",
  "price": 376,
  "tax": 25,
  "shipping_cost": 56
}, {
  "id": 51,
  "name": "in tempor turpis",
  "color": "Mauv",
  "gender": "Male",
  "size": "M",
  "price": 328,
  "tax": 25,
  "shipping_cost": 70
}, {
  "id": 52,
  "name": "justo lacinia",
  "color": "Yellow",
  "gender": "Female",
  "size": "L",
  "price": 468,
  "tax": 25,
  "shipping_cost": 48
}, {
  "id": 53,
  "name": "pede",
  "color": "Red",
  "gender": "Female",
  "size": "L",
  "price": 488,
  "tax": 25,
  "shipping_cost": 46
}, {
  "id": 54,
  "name": "ligula in",
  "color": "Green",
  "gender": "Male",
  "size": "S",
  "price": 397,
  "tax": 25,
  "shipping_cost": 72
}, {
  "id": 55,
  "name": "ut",
  "color": "Goldenrod",
  "gender": "Male",
  "size": "S",
  "price": 423,
  "tax": 25,
  "shipping_cost": 56
}, {
  "id": 56,
  "name": "placerat praesent blandit",
  "color": "Teal",
  "gender": "Male",
  "size": "2XL",
  "price": 433,
  "tax": 25,
  "shipping_cost": 57
}, {
  "id": 57,
  "name": "vel",
  "color": "Blue",
  "gender": "Male",
  "size": "XL",
  "price": 396,
  "tax": 25,
  "shipping_cost": 41
}, {
  "id": 58,
  "name": "nisl",
  "color": "Pink",
  "gender": "Male",
  "size": "3XL",
  "price": 422,
  "tax": 25,
  "shipping_cost": 69
}, {
  "id": 59,
  "name": "nunc",
  "color": "Yellow",
  "gender": "Male",
  "size": "S",
  "price": 411,
  "tax": 25,
  "shipping_cost": 71
}, {
  "id": 60,
  "name": "ut odio cras",
  "color": "Mauv",
  "gender": "Female",
  "size": "M",
  "price": 433,
  "tax": 25,
  "shipping_cost": 55
}, {
  "id": 61,
  "name": "quisque id justo",
  "color": "Pink",
  "gender": "Male",
  "size": "2XL",
  "price": 498,
  "tax": 25,
  "shipping_cost": 45
}, {
  "id": 62,
  "name": "praesent",
  "color": "Puce",
  "gender": "Male",
  "size": "XS",
  "price": 403,
  "tax": 25,
  "shipping_cost": 63
}, {
  "id": 63,
  "name": "potenti",
  "color": "Mauv",
  "gender": "Female",
  "size": "S",
  "price": 418,
  "tax": 25,
  "shipping_cost": 45
}, {
  "id": 64,
  "name": "tempor convallis",
  "color": "Green",
  "gender": "Male",
  "size": "3XL",
  "price": 376,
  "tax": 25,
  "shipping_cost": 53
}, {
  "id": 65,
  "name": "bibendum felis",
  "color": "Goldenrod",
  "gender": "Male",
  "size": "XS",
  "price": 361,
  "tax": 25,
  "shipping_cost": 41
}, {
  "id": 66,
  "name": "nulla suscipit ligula",
  "color": "Puce",
  "gender": "Female",
  "size": "L",
  "price": 327,
  "tax": 25,
  "shipping_cost": 46
}, {
  "id": 67,
  "name": "elementum pellentesque quisque",
  "color": "Red",
  "gender": "Female",
  "size": "XL",
  "price": 422,
  "tax": 25,
  "shipping_cost": 57
}, {
  "id": 68,
  "name": "primis",
  "color": "Yellow",
  "gender": "Male",
  "size": "XL",
  "price": 302,
  "tax": 25,
  "shipping_cost": 62
}, {
  "id": 69,
  "name": "integer",
  "color": "Turquoise",
  "gender": "Male",
  "size": "XS",
  "price": 313,
  "tax": 25,
  "shipping_cost": 58
}, {
  "id": 70,
  "name": "ultrices erat",
  "color": "Orange",
  "gender": "Male",
  "size": "2XL",
  "price": 497,
  "tax": 25,
  "shipping_cost": 69
}, {
  "id": 71,
  "name": "porttitor id",
  "color": "Teal",
  "gender": "Male",
  "size": "XL",
  "price": 395,
  "tax": 25,
  "shipping_cost": 47
}, {
  "id": 72,
  "name": "augue aliquam",
  "color": "Aquamarine",
  "gender": "Male",
  "size": "XS",
  "price": 331,
  "tax": 25,
  "shipping_cost": 74
}, {
  "id": 73,
  "name": "platea dictumst",
  "color": "Red",
  "gender": "Male",
  "size": "S",
  "price": 480,
  "tax": 25,
  "shipping_cost": 72
}, {
  "id": 74,
  "name": "mauris",
  "color": "Fuscia",
  "gender": "Female",
  "size": "L",
  "price": 417,
  "tax": 25,
  "shipping_cost": 60
}, {
  "id": 75,
  "name": "id",
  "color": "Turquoise",
  "gender": "Male",
  "size": "XL",
  "price": 305,
  "tax": 25,
  "shipping_cost": 41
}, {
  "id": 76,
  "name": "posuere",
  "color": "Pink",
  "gender": "Female",
  "size": "M",
  "price": 422,
  "tax": 25,
  "shipping_cost": 55
}, {
  "id": 77,
  "name": "amet",
  "color": "Pink",
  "gender": "Female",
  "size": "XS",
  "price": 473,
  "tax": 25,
  "shipping_cost": 65
}, {
  "id": 78,
  "name": "a pede posuere",
  "color": "Maroon",
  "gender": "Female",
  "size": "M",
  "price": 329,
  "tax": 25,
  "shipping_cost": 60
}, {
  "id": 79,
  "name": "turpis donec posuere",
  "color": "Green",
  "gender": "Female",
  "size": "M",
  "price": 446,
  "tax": 25,
  "shipping_cost": 66
}, {
  "id": 80,
  "name": "est phasellus",
  "color": "Crimson",
  "gender": "Female",
  "size": "L",
  "price": 453,
  "tax": 25,
  "shipping_cost": 61
}, {
  "id": 81,
  "name": "convallis eget eleifend",
  "color": "Blue",
  "gender": "Male",
  "size": "2XL",
  "price": 431,
  "tax": 25,
  "shipping_cost": 68
}, {
  "id": 82,
  "name": "eget",
  "color": "Maroon",
  "gender": "Male",
  "size": "S",
  "price": 446,
  "tax": 25,
  "shipping_cost": 72
}, {
  "id": 83,
  "name": "et eros",
  "color": "Green",
  "gender": "Male",
  "size": "XS",
  "price": 468,
  "tax": 25,
  "shipping_cost": 56
}, {
  "id": 84,
  "name": "donec ut dolor",
  "color": "Crimson",
  "gender": "Male",
  "size": "L",
  "price": 382,
  "tax": 25,
  "shipping_cost": 68
}, {
  "id": 85,
  "name": "ut",
  "color": "Khaki",
  "gender": "Male",
  "size": "S",
  "price": 320,
  "tax": 25,
  "shipping_cost": 68
}, {
  "id": 86,
  "name": "ipsum dolor",
  "color": "Crimson",
  "gender": "Female",
  "size": "M",
  "price": 404,
  "tax": 25,
  "shipping_cost": 59
}, {
  "id": 87,
  "name": "pede posuere",
  "color": "Mauv",
  "gender": "Male",
  "size": "XL",
  "price": 416,
  "tax": 25,
  "shipping_cost": 47
}, {
  "id": 88,
  "name": "eget tempus vel",
  "color": "Teal",
  "gender": "Female",
  "size": "XS",
  "price": 373,
  "tax": 25,
  "shipping_cost": 58
}, {
  "id": 89,
  "name": "ligula in lacus",
  "color": "Yellow",
  "gender": "Male",
  "size": "M",
  "price": 398,
  "tax": 25,
  "shipping_cost": 68
}, {
  "id": 90,
  "name": "ultrices mattis odio",
  "color": "Red",
  "gender": "Male",
  "size": "XS",
  "price": 379,
  "tax": 25,
  "shipping_cost": 40
}, {
  "id": 91,
  "name": "magnis dis parturient",
  "color": "Teal",
  "gender": "Male",
  "size": "XS",
  "price": 360,
  "tax": 25,
  "shipping_cost": 69
}, {
  "id": 92,
  "name": "cubilia curae",
  "color": "Goldenrod",
  "gender": "Female",
  "size": "XL",
  "price": 312,
  "tax": 25,
  "shipping_cost": 64
}, {
  "id": 93,
  "name": "posuere",
  "color": "Pink",
  "gender": "Female",
  "size": "XS",
  "price": 445,
  "tax": 25,
  "shipping_cost": 66
}, {
  "id": 94,
  "name": "duis bibendum",
  "color": "Khaki",
  "gender": "Male",
  "size": "XL",
  "price": 406,
  "tax": 25,
  "shipping_cost": 54
}, {
  "id": 95,
  "name": "consectetuer adipiscing elit",
  "color": "Khaki",
  "gender": "Female",
  "size": "L",
  "price": 493,
  "tax": 25,
  "shipping_cost": 60
}, {
  "id": 96,
  "name": "praesent",
  "color": "Orange",
  "gender": "Female",
  "size": "2XL",
  "price": 329,
  "tax": 25,
  "shipping_cost": 45
}, {
  "id": 97,
  "name": "sit amet consectetuer",
  "color": "Orange",
  "gender": "Female",
  "size": "M",
  "price": 401,
  "tax": 25,
  "shipping_cost": 42
}, {
  "id": 98,
  "name": "nisi volutpat",
  "color": "Blue",
  "gender": "Female",
  "size": "S",
  "price": 455,
  "tax": 25,
  "shipping_cost": 48
}, {
  "id": 99,
  "name": "ac enim",
  "color": "Khaki",
  "gender": "Male",
  "size": "S",
  "price": 351,
  "tax": 25,
  "shipping_cost": 50
}, {
  "id": 100,
  "name": "odio elementum",
  "color": "Maroon",
  "gender": "Male",
  "size": "XS",
  "price": 390,
  "tax": 25,
  "shipping_cost": 57
}]

function App() {
  return (
    <>
      <AppHeader />
      <ul>
        {/* Filtering all blue t-shirts, and then changing the names to uppercase. */}
         {tshirts
            .filter((x) => x.color === 'Blue')
            .map(x => <DisplayDataArea name={x.name.charAt(0)
            .toUpperCase() + x.name.slice(1)} color={x.color} price={x.price} />)
         }
      </ul>
      <OrderArea />
    </>
  )
}

function AppHeader() {
  return <h1>T-shirt App</h1>
}

function DisplayDataArea(props) {
  return (
    <>
      <li>
        <span class="property"><b>Name:</b></span> {props.name} 
        <span class="property"><b>Colour: </b></span> {props.color} 
        <span class="property"><b>Price:</b></span> {props.price} SEK
      </li>
    </>
  )
}

function OrderArea() {
  // useState returns an array with 2 items. So here we are destructuring the array into 2 variables, in this case named counter and setCount. setCount is a method that will update the value of the state data
  const [counter, setCount] = useState(0)
  
  function increaseCount() {
    setCount(function(prev) {
      return prev + 1
    })
  }
  
  function decreaseCount() {
    setCount(function(prev){
      if(prev > 0) {
        return prev -1
      }
      return 0
    })
  }
  
  
  return (
    <h3>I want to order {counter} T-shirt(s) <button onClick={increaseCount}>+</button> <button onClick={decreaseCount}>-</button></h3>
    )
  
}

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

Console