diff --git a/track-tutorial-react-js/src/App.js b/track-tutorial-react-js/src/App.js index ff2e383..8ff3ca5 100644 --- a/track-tutorial-react-js/src/App.js +++ b/track-tutorial-react-js/src/App.js @@ -1,19 +1,42 @@ -import React, { useState } from 'react'; +import React, { useState } from "react"; import TrackButton from "./components/TrackButton"; import TrackText from "./components/TrackText"; function App() { const [text, setText] = useState(""); + const [list, setList] = useState([]); + const onClick = () => { - setText("hello track"); - } + if (text.trim() !== "") { + setList([...list, text]); + setText(""); // 追加後に入力フィールドをクリア + } + }; + + const onDelete = (index) => { + const newList = list.filter((_, i) => i !== index); + setList(newList); + }; return ( -
+
+ setText(e.target.value)} + placeholder="Enter text here" + /> - + + +
    + {list.map((item, index) => ( +
  • + {item} + +
  • + ))} +
); }