-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
62 lines (50 loc) · 1.15 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
import React, { useState } from "react";
import TodoList from'./TodoList';
const App = () => {
const [inputList, setInputList] = useState("");
const [Items, setItems] = useState([]);
const itemEvent = (event) => {
setInputList(event.target.value);
};
const listOfItem = () =>{
setItems((oldItems)=>{
return [...oldItems, inputList];
});
setInputList('');
};
const deleteItmes = (id) => {
console.log("deleted");
setItems((oldItems) =>{
return oldItems.filter((arrElem, index)=> {
return index !== id;
})
})
};
return(
<>
<div className="main_div">
<div className="center_div">
<br />
<h1> ToDo List</h1>
<br />
<input type="text" placeholder="Add Item"
value={inputList}
onChange={itemEvent}/>
<button onClick={listOfItem}> + </button>
<ol>
{/*<li>{inputList}</li>*/}
{Items.map( (itemval, index) => {
return <TodoList
key={index}
id={index}
text= {itemval}
onSelect = {deleteItmes}
/>;
} )}
</ol>
</div>
</div>
</>
);
};
export default App;