diff --git a/denam host b/denam host new file mode 100644 index 0000000..64181e9 --- /dev/null +++ b/denam host @@ -0,0 +1,83 @@ +import React, { useState, useEffect } from "react"; + +export default function TodoApp() { + const [todos, setTodos] = useState(() => + JSON.parse(localStorage.getItem("todos") || "[]") + ); + const [input, setInput] = useState(""); + + // Save todos to localStorage whenever they change + useEffect(() => { + localStorage.setItem("todos", JSON.stringify(todos)); + }, [todos]); + + const addTodo = (e) => { + e.preventDefault(); + if (!input.trim()) return; + setTodos([...todos, { id: Date.now(), text: input, done: false }]); + setInput(""); + }; + + const toggleTodo = (id) => { + setTodos(todos => + todos.map(todo => + todo.id === id ? { ...todo, done: !todo.done } : todo + ) + ); + }; + + const deleteTodo = (id) => { + setTodos(todos => todos.filter(todo => todo.id !== id)); + }; + + return ( +