Last active
December 7, 2021 11:12
-
-
Save omas-public/102e05a6f2a040e4f514eeee60d5f681 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import React, { useState, useEffect } from "react"; | |
| import axios from "axios"; | |
| const todoDataUrl = "http://localhost:3100/todos"; | |
| function App() { | |
| const [todoList, setTodoList] = useState([]); | |
| useEffect(() => { | |
| const fetchData = async () => { | |
| const response = await axios.get(todoDataUrl); | |
| setTodoList(response.data); | |
| }; | |
| fetchData(); | |
| }, []); | |
| console.log("TODOリスト:", todoList); | |
| const inCompletedList = todoList.filter((todo) => { | |
| return !todo.done; | |
| }); | |
| console.log("未完了TODOリスト:", inCompletedList); | |
| const completedList = todoList.filter((todo) => { | |
| return todo.done; | |
| }); | |
| console.log("完了TODOリスト:", completedList); | |
| return ( | |
| <> | |
| <h1>TODO進捗管理</h1> | |
| <textarea /> | |
| <button>+ TODOを追加</button> | |
| <h2>未完了TODOリスト</h2> | |
| <ul> | |
| {inCompletedList.map((todo) => ( | |
| <li key={todo.id}> | |
| {todo.content} | |
| <button>{todo.done ? "未完了リストへ" : "完了リストへ"}</button> | |
| <button>削除</button> | |
| </li> | |
| ))} | |
| </ul> | |
| <h2>完了TODOリスト</h2> | |
| <ul> | |
| {completedList.map((todo) => ( | |
| <li key={todo.id}> | |
| {todo.content} | |
| <button>{todo.done ? "未完了リストへ" : "完了リストへ"}</button> | |
| <button>削除</button> | |
| </li> | |
| ))} | |
| </ul> | |
| </> | |
| ); | |
| } | |
| export default App; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment