-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.jsx
More file actions
38 lines (30 loc) · 910 Bytes
/
App.jsx
File metadata and controls
38 lines (30 loc) · 910 Bytes
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
import {useCallback, useState, useMemo} from 'react';
import NoteInput from "./components/NoteInput";
import NoteList from "./components/NoteList";
import NoteItem from "./components/NoteItem.jsx";
function App() {
const [notes, setNotes] = useState([]);
const addNote = (text) => {
setNotes((previousNotes) => [...previousNotes, {
id: Date.now(),
text
}])
}
const onDelete = useCallback((id) => {
setNotes((previousNotes) => previousNotes.filter((note) => note.id !== id));
}, [])
const totalNotes = useMemo(() => notes.length, [notes]);
return (
<div>
<NoteInput
onAdd={addNote}
/>
<NoteList
notes={notes}
onDelete={onDelete}
/>
<h2>Total notes: {totalNotes}</h2>
</div>
);
}
export default App;