-
Notifications
You must be signed in to change notification settings - Fork 5
/
App2.js
39 lines (32 loc) · 929 Bytes
/
App2.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
30
31
32
33
34
35
36
37
38
39
import React, { useState, useEffect } from 'react';
import { Container, Input } from 'reactstrap';
import 'bootstrap/dist/css/bootstrap.min.css';
import './App.css';
import InputForm from './components/InputForm';
import Todo from './components/Todo';
const App = () => {
const [todos, setTodos] = useState([])
useEffect(() => {
const localTodos = localStorage.getItem("todos")
if (localTodos) {
setTodos(JSON.parse(localTodos))
}
}, [])
const addTodos = async todo => {
setTodos([...todos, todo])
}
useEffect(() => {
localStorage.setItem("todos", JSON.stringify(todos))
}, [todos])
const completedFlag = (id) => {
setTodos(todos.filter(todo => todo.id !== id))
}
return (
<Container type="fluid">
<h1>My Todo App</h1>
<InputForm addTodos={addTodos} />
<Todo todos={todos} completedFlag={completedFlag} />
</Container>
);
}
export default App;