-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhints.js
46 lines (35 loc) · 1.22 KB
/
hints.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
// With hooks, the old state is REPLACED by the one that triggers the event.
// To correct that, you’ll need to copy the entire properties from the old state
// using the spread operator (…) and override the part of it that is the new.
const handleChange = (e) => {
setCard({
...card,
[e.target.name]: e.target.value,
});
};
// Using Object.keys: check out this article:
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys
const getTodoStorage = () => {
let cards = [],
keys = Object.keys(localStorage),
i = keys.length;
while ( i-- ) {
cards.push(JSON.parse(localStorage.getItem(keys[i])));
}
return cards;
}
// Homepage navigation of buttons
import { useNavigate } from 'react-router-dom';
const Homepage = () => {
const navigate = useNavigate();
return (
<div className="homepage">
<h1>This is a To Do app, created with React</h1>
<div className="button-set">
<button className="nav-button" onClick={() => navigate("/todo")}>Create new To Do</button>
<button className="nav-button" onClick={() => navigate("/todooverview")}>To Do Overview</button>
</div>
</div>
);
};
export default Homepage;