-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.js
More file actions
59 lines (52 loc) · 1.66 KB
/
App.js
File metadata and controls
59 lines (52 loc) · 1.66 KB
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
import React,{useState} from "react";
import Todo from "./Todo";
function App() {
const [inputList, setInputList] = useState("");
const [items, setItems] = useState([]);
const itemEvent=(event)=>{
setInputList(event.target.value);
};
const listOfItems= ()=>{
setItems((item)=>{
return [...item,inputList];
});
setInputList("");
};
const myStyle = {
backgroundColor: "#319B9D",
height: '100vh',
};
const deleteItem=(id)=>{
setItems((item)=>{
return item.filter((elem,index)=>{
return index!==id;
});
});
}
return (
<>
<div className="position-relative" style={myStyle}>
<div className="position-absolute top-50 start-50 translate-middle">
<div className="card" style={{ width: "18rem" }}>
<div className="card-body">
<h5 className="card-title text-center"><span className="bg-warning"> ToDo List </span></h5>
<div className="form-floating mb-3">
<input type="text" class="form-control" id="floatingInput" placeholder="xyz.." value={inputList} onChange={itemEvent}/>
<label for="floatingInput">Add an Item</label>
</div>
<button className="btn btn-success" onClick={listOfItems}><i className="fas fa-plus-circle"/></button>
<ul className="list-group my-2">
{
items.map((itemVal,index)=>{
return <Todo key={index} id={index} text={itemVal} onSelect={deleteItem}/>
})
}
</ul>
</div>
</div>
</div>
</div>
</>
);
}
export default App;