import * as React from "react"; import { ToDoData } from "./TodoData"; export const Todo = () => { const [items, setItems] = React.useState([ new ToDoData("Learn JavaScript"), new ToDoData("Learn React"), new ToDoData("Get some good sleep") ]); return (
️ React ToDo
{items.map((item) => ( ))}
{items.length} items
); }; import * as React from "react"; import { TodoData } from "./TodoData"; import { TodoItem } from "./TodoItem"; export const Todo = () => { const [items, setItems] = React.useState([ new TodoData("Learn JavaScript"), new TodoData("Learn React"), new TodoData("Get some good sleep") ]); const onCheck = (item: TodoData, checked: boolean) => { // 該当するitemを更新 const newItems = items.map((value) => { if (value.key !== item.key) return value; return new TodoData(value.text, checked); }); setItems(newItems); }; return (
️ React ToDo
{items.map((item) => ( ))}
{items.length} items
); }; import * as React from "react"; import { TodoList } from "./TodoList"; import { TodoData } from "./TodoData"; import { Input } from "./Input"; export const Todo = () => { const [items, setItems] = React.useState([ new TodoData("Learn JavaScript"), new TodoData("Learn React"), new TodoData("Get some good sleep") ]); const onCheck = (item: TodoData, checked: boolean) => { // 該当するitemを更新 const newItems = items.map((value) => { if (value.key !== item.key) return value; return new TodoData(value.text, checked); }); setItems(newItems); }; const onAdd = (text: string) => setItems([...items, new TodoData(text)]); return (
️ React ToDo
); };