forked from EFUB/efub4-frontend-assignment-1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
29 lines (24 loc) ยท 751 Bytes
/
App.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import Header from "./Header";
import TodoList from "./TodoList";
import TodoAdd from "./TodoAdd";
import logo from './logo.svg';
import React, {useEffect, useState} from "react";
import './App.css';
const TODO_LIST_KEY="todoList";
function App() {
const [todoList,setTodoList]=useState(()=>{
const savedTodoList=localStorage.getItem(TODO_LIST_KEY);
return savedTodoList?JSON.parse(savedTodoList):[];
});
useEffect(()=>{
localStorage.setItem(TODO_LIST_KEY,JSON.stringify(todoList));
},[todoList]);
return (
<div className="App">
<Header/>
<TodoAdd todoList={todoList} setTodoList={setTodoList}/>
<TodoList todoList={todoList} setTodoList={setTodoList}/>
</div>
);
}
export default React.memo(App);