diff --git a/src/App.jsx b/src/App.jsx index 727abb9..8237b30 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -1,22 +1,18 @@ import { useState } from "react"; import "./styles.css"; +import { NewTodoForm } from "./newtodoform"; +import { TodoList } from "./todolist"; export default function App() { - const [newItem, setNewItem] = useState(""); const [todos, setTodos] = useState([]); - function handleSubmit(e) { - e.preventDefault(); - const title = newItem.trim(); - if (!title) return; - + function addTodo(title) { setTodos((currentTodos) => { return [ ...currentTodos, { id: crypto.randomUUID(), title, completed: false }, ]; }); - setNewItem(""); } function toggleTodo(id, completed) { @@ -33,46 +29,10 @@ export default function App() { return (
-
- - - setNewItem(e.target.value)} - type="text" - id="Item" - className="input" - /> - - -
+

Todo List

- - +
); } diff --git a/src/newtodoform.jsx b/src/newtodoform.jsx index 0bf9575..04beba8 100644 --- a/src/newtodoform.jsx +++ b/src/newtodoform.jsx @@ -1,20 +1,32 @@ -export function NewTodoForm() { - return( +import { useState } from "react"; +export function NewTodoForm({ onSubmit }) { + const [newItem, setNewItem] = useState(""); + + function handleSubmit(e) { + e.preventDefault(); + const title = newItem.trim(); + if (!title) return; + + onSubmit(title); + setNewItem(""); + } + + return (
- + - setNewItem(e.target.value)} - type="text" - id="Item" - className="input" - /> + setNewItem(e.target.value)} + type="text" + id="Item" + className="input" + /> - -
- ) + + + ); } diff --git a/src/todoitem.jsx b/src/todoitem.jsx new file mode 100644 index 0000000..b80aecf --- /dev/null +++ b/src/todoitem.jsx @@ -0,0 +1,18 @@ +export function TodoItem({ todo, onToggle, onDelete }) { + return ( +
  • + + + +
  • + ); +} diff --git a/src/todolist.jsx b/src/todolist.jsx new file mode 100644 index 0000000..efcca36 --- /dev/null +++ b/src/todolist.jsx @@ -0,0 +1,26 @@ +export function TodoList({ todos, onToggle, onDelete }) { + return ( + + ); +}