React アプリケーション完成版

index.html

<!DOCTYPE html>
<html lang="ja">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>My React App</title>
  <script src="https://unpkg.com/react@18/umd/react.development.js"></script>
  <script src="https://unpkg.com/react-dom@18/umd/react-dom.development.js"></script>
  <script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
  <link rel="stylesheet" href="style.css">
</head>

<body>
  <div id="container"></div>

  <script type="text/babel">
    'use strict';

    {
      const Menu = (props) => {

        const decrement = () => {

          props.onDecrement(props.menuId);
        };
        const increment = () => {
          props.onIncrement(props.menuId);
        };

        return (
          <li>
            <button onClick={decrement}>-</button>
            <button onClick={increment}>+</button>
            {props.name} ({props.price}G ☓ {props.count}個)
          </li>
        );
      };

      const App = () => {
        const [counts, setCounts] = React.useState([0, 0, 0]);
        const menus = [
          { id: 0, name: 'ポーション', price: 400 },
          { id: 1, name: 'ハイポーション', price: 500 },
          { id: 2, name: 'エリクサー', price: 300 },
        ];
        const total =
          (menus[0].price * counts[0]) +
          (menus[1].price * counts[1]) +
          (menus[2].price * counts[2]);
        const decrementMenu = (menuId) => {
          if(counts[menuId] > 0){
          const newCounts = [...counts];
          newCounts[menuId]--;
          setCounts(newCounts);
          }
        };
        const incrementMenu = (menuId) => {
          const newCounts = [...counts];
          newCounts[menuId]++;
          setCounts(newCounts);
        };
        const menuItems = menus.map((menu) => {
          return (
            <Menu
              key={menu.id}
              menuId={menu.id}
              count={counts[menu.id]}
              name={menu.name}
              price={menu.price}
              onDecrement={decrementMenu}
              onIncrement={incrementMenu}
            />
          );
        });

        return (
          <>
            <h1>メニュー</h1>
            <ul className="menus">
              {menuItems}
            </ul>
            <p>合計: {total}G</p>
          </>
        );
      };

      const container = document.querySelector('#container');
      const root = ReactDOM.createRoot(container);
      root.render(<App />);
    }
  </script>
</body>

</html>

style.css

@charset "utf-8";

body{
    margin: 0;
}

#container{
    width: 400px;
    margin: auto;
}

h1{
    margin: 16px 0 0 0;
    font-size: 20px;
    text-align: center;
}

.menus{
    margin: 0;
    padding: 0;
    list-style-type: none;
}

.menus > li{
    border: 1px solid #ccc;
    padding: 8px;
    border-radius: 8px;
    margin-top: 16px;
}

.menus button{
    margin-right: 8px;
    width: 24px;
}
p{
    margin: 0;
    text-align: right;
}

投稿者: chosuke

趣味はゲームやアニメや漫画などです

「React アプリケーション完成版」への23件のフィードバック

  1. My reading list is short and selective and this site is now on it, and a stop at shadowglowcorner confirmed the placement, the short list of sites I read deliberately rather than encounter accidentally is something I curate carefully and adding to it is a real act of trust which this site has earned today.

  2. Reading this slowly because the writing rewards a slower pace, and a stop at clevercartarena did the same, the pace at which I read content is something I now use as a quality signal and writing that earns a slower pace earns my attention as a reader looking for substance these days.

  3. A piece that prompted a small mental rearrangement of how I order related ideas, and a look at crystalpetalcollective extended that rearranging effect, content that affects the structure of my thinking rather than just adding to it is content with the deepest kind of impact and this site is reaching that depth for me today.

  4. Quiet confidence runs through the whole post, no need to shout to make the points stick, and a stop at aurorastreetgoods carried that same restrained voice forward, content that respects the reader by trusting its own substance rather than dressing it up in theatrical language is what I look for online and rarely actually find these days.

  5. Reading this on a long flight and finding it the best thing I read across hours of trying, and a stop at urbanpinebazaar kept the streak going, when content beats long flight reading you know it has substance because flight reading is a hard test of a piece given the alternatives available everywhere.

  6. Really like that the writer trusts the reader to follow simple logic without restating every previous point, and a stop at shadowglowcorner kept that respect going, treating an audience as capable adults rather than as people who need constant hand holding makes a noticeable difference in the reading experience for me.

  7. Now noticing that the post did not mention the writer at all, focus stayed on the topic, and a look at twilightgrovegoods continued that author absent quality, content that disappears the writer to focus on the substance is a particular kind of generosity and this site has clearly chosen the substance over the personality consistently.

  8. Quality you can feel from the first paragraph, the writer clearly knows the topic and how to share it, and a quick look at fasttrendcorner confirmed the same depth runs throughout the rest of the site as well which is rare and worth pointing out when it happens online for any reader passing through.

  9. Now noticing that the post never raised its voice even when making a strong point, and a look at twilightcreststore continued that calm volume, content that can make important points without resorting to typographic emphasis or emotional appeal is content that trusts its substance to do the work and this site has that confidence consistently.

  10. After several visits I am now confident this site is one to follow seriously, and a stop at moderntrendcenter reinforced that confidence, the gradual building of trust through repeated quality exposures is the only sustainable way to develop reader loyalty and this site is building that loyalty in me through patient consistent work consistently.

  11. Just enjoyed the experience without needing to think about why, and a look at stonelightemporium kept that effortless feeling going, sometimes the best content is invisible in the sense that you forget you are reading until you reach the end and realise time has passed without you noticing it pass naturally.

  12. Reading this prompted me to dig out an old reference book related to the topic, and a stop at qualitycartarena extended that connection to other sources, content that connects me back to my own existing knowledge rather than asking me to forget it is content with continuity and this site has that continuous quality.

  13. Found the section structure particularly thoughtful, and a stop at silverhorizonstore suggested the same care across the broader site, structural choices guide the reader through the material in ways most people do not consciously notice but feel the absence of when those choices are made carelessly or not at all.

  14. Picked up a couple of new ideas here that I can actually try out, and after my visit to freshcartcorner I have even more notes saved, this is the kind of resource that pays you back for the time you spend on it which is rare to come across in this corner of the web.

  15. Reading the writers other posts after this one suggests the quality is consistent rather than peak, and a stop at premiumpickzone confirmed the consistent quality reading, sites that hold the same level across many pieces rather than peaking on a few are sites with sustainable editorial discipline and this one has clearly developed that.

  16. Reading this triggered a small reorganisation of my own thinking on the topic, and a stop at dreamwovenbazaar furthered that reorganisation, content that affects the shape of my mental model rather than just decorating it with new facts is content with structural rather than informational impact and this site provides that.

  17. Useful read, especially because the writer did not assume too much background from the reader, and a quick look at epiccartcenter continued in the same way, a thoughtful site that meets people where they are which is something the modern web could use a lot more of for both casual and serious readers.

  18. Closed the laptop after this and let the ideas settle for a few hours, and a stop at copperwindessentials similarly rewarded reflective time, content that benefits from sitting with rather than racing past is the kind I want more of and the kind that this site appears to consistently produce week after week here.

  19. Reading this confirmed a hunch I had been carrying about the topic without having articulated it, and a stop at silversproutstore extended the confirmation, content that gives shape to fuzzy intuitions is doing the rare work of making private thoughts public and this site is providing that articulating service consistently for me lately.

  20. Reading this slowly to absorb the structure, and the structure is doing real work alongside the words, and a look at infinitybuyhub maintained the same architectural quality, when sentence shapes and paragraph rhythms reinforce the meaning rather than just transporting words you know you are reading skilled work today.

  21. Took a quick scan first and then went back to read properly because the post deserved it, and a stop at neonpickmarket kept me reading carefully too, the kind of writing that earns a slower second pass rather than getting skimmed and forgotten is something I value highly when I happen to find it.

  22. Recommended without reservation for anyone interested in the topic at any level of expertise, and a look at perfectbuycorner only strengthens that recommendation, this site clearly knows how to serve readers across a range of backgrounds without watering down the content or talking past anyone in the audience which is genuinely impressive to see.

  23. Just wanted to drop a quick note saying this was a useful read on a topic I have been circling, no fluff, and a stop at crystalbloommarket added a few extra points that fit the same simple style which makes the whole site feel coherent rather than thrown together by many different writers with different goals.

コメントを残す

メールアドレスが公開されることはありません。 ※ が付いている欄は必須項目です