-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.jsx
More file actions
70 lines (57 loc) · 1.59 KB
/
Copy pathApp.jsx
File metadata and controls
70 lines (57 loc) · 1.59 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
60
61
62
63
64
65
66
67
68
69
70
import React from "react";
import Header from "./Header";
import Footer from "./Footer";
import Note from "./Note";
import CreateArea from "./CreateArea";
function App() {
const [titleInput, setTitleInput] = React.useState("");
const [contentInput, setContentInput] = React.useState("");
// const {titleAndContent, setTitleAndContent} = React.useState({
// title : "",
// content: ""
// })
function handleChange(event){
if (event.target.name === "title"){
const newTitle = event.target.value ;
return setTitleInput(newTitle);
} else if (event.target.name === "content"){
const newContent = event.target.value ;
return setContentInput(newContent) ;
}
}
const [listItems, setListItems] = React.useState([]);
function addition(event) {
event.preventDefault();
setTitleInput("");
setContentInput("");
return setListItems((preValue) => {
return [
...preValue,
{
title: titleInput,
content: contentInput
}
]
})
}
function deleteItem(id){
return setListItems((preValue)=>{
return preValue.filter((each, index) =>{
return index !== id
})
})
}
return (
<div>
<Header />
<CreateArea onAddition={addition} handleChange={handleChange} titleInput={titleInput} contentInput={contentInput} />
{
listItems.map((eachItem, index) => {
return <Note key={index} id={index} title={eachItem.title} content={eachItem.content} onDeleteItem={deleteItem} />
})
}
<Footer />
</div>
);
}
export default App;