Daten der Todo Apps persistiert
This commit is contained in:
@@ -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 = {
|
||||
|
||||
Reference in New Issue
Block a user