From 529c3f55b96e6fc5fc19300599deb79cb9f41757 Mon Sep 17 00:00:00 2001 From: Rock3r Date: Mon, 27 Apr 2026 14:28:04 +0200 Subject: [PATCH] feat(storage): persist task to localStorage using useEffect and lazy init --- src/App.tsx | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index e9611f8..d8e76c0 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,11 +1,19 @@ -import { useState } from "react" +import { useEffect, useState } from "react" import type { Task } from "./types/task"; import { TaskItem } from "./components/TaskItem"; function App() { - const [tasks, setTasks] = useState([]); + const [tasks, setTasks] = useState(() => { + const savedTasks = localStorage.getItem('tasks'); + return savedTasks ? JSON.parse(savedTasks) : [] + }); + const [inputValue, setInputValue] = useState(''); + useEffect(() => { + localStorage.setItem('tasks', JSON.stringify(tasks)); + }, [tasks]); + const addTask = () => { if (inputValue.trim() === '') return;