Daten der Todo Apps persistiert

This commit is contained in:
Max
2026-07-15 08:50:49 +02:00
parent 497ab442f2
commit 451e0de4ff
4 changed files with 47 additions and 7 deletions
+9 -1
View File
@@ -3,8 +3,16 @@ import TodoForm from "./components/TodoForm";
import TodoList from "./components/TodoList";
import "./App.css";
const STORAGE_STRING = 'todo-app2-todos';
function App() {
const [todos, setTodos] = useState([]);
const [todos, setTodos] = useState(JSON.parse(localStorage.getItem(STORAGE_STRING)) || []);
useEffect(() => persistTodos(), [todos]);
function persistTodos() {
localStorage.setItem(STORAGE_STRING, JSON.stringify(todos));
}
function addTodo(text, priority) {
const newTodo = {