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) => {
return (
<li>
<button>-</button>
<button>+</button>
{props.name}({props.price}G X 0個)
</li>
);
};
const App = () => {
const menus = [
{id: 0,name: '聖剣', price: 400},
{id: 1,name: '魔装銃', price: 500},
{id: 2,name: '魔剣', price: 300},
];
const menuItems = menus.map((menu) =>{
return(
<Menu
key={menu.id}
name={menu.name}
price={menu.price}
/>
);
});
return (
<>
<h1>メニュー</h1>
<ul className="menus">
{menuItems}
</ul>
<p>合計: 0円</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;
}