-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathApp.js
75 lines (72 loc) · 1.85 KB
/
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import "./App.css";
import React, { useEffect, useState } from "react";
import axios from "axios";
import ToDo from "./todo";
import PopUp from "./popup";
const baseURL = "http://localhost:8005/api";
function App() {
const [todos, settodos] = useState([]);
const [input, setinput] = useState("");
const [updateUI, setupdateUi] = useState(false);
const [showpopup, setshowpopup] = useState(false);
const [popupvalue, setpopupvalue] = useState({});
useEffect(() => {
axios
.get(`${baseURL}/get`)
.then((res) => {
settodos(res.data);
})
.catch((err) => {
console.log(err);
});
}, [updateUI]);
const saveToDo = () => {
axios
.post(`${baseURL}/save`, { todo: input })
.then((res) => {
console.log(res.data);
setupdateUi((prevState) => !prevState);
setinput("");
})
.catch((err) => {
console.log(err);
});
};
return (
<div className="main">
<div className="container">
<h1>To Do List</h1>
<div className="inputtodo">
<input
value={input}
onChange={(e) => {
setinput(e.target.value);
}}
placeholder="Enter a task..."
></input>
<button onClick={saveToDo}>Add</button>
</div>
<div className="listtodo">
{todos.map((el) => (
<ToDo
key={el._id}
text={el.todo}
id={el._id}
setupdateUI={setupdateUi}
setshowpopup={setshowpopup}
setpopupvalue={setpopupvalue}
></ToDo>
))}
</div>
</div>
{showpopup && (
<PopUp
setshowpopup={setshowpopup}
popupvalue={popupvalue}
setupdateUI={setupdateUi}
></PopUp>
)}
</div>
);
}
export default App;