-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path14.state.array.html
More file actions
55 lines (51 loc) · 1.3 KB
/
14.state.array.html
File metadata and controls
55 lines (51 loc) · 1.3 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
<!DOCTYPE html>
<html>
<head>
<title>state</title>
<meta charset="utf-8" />
<style>
body {
font-family: -apple-system, sans-serif;
}
</style>
</head>
<body>
<div id="app"></div>
<script src="react/react.js"></script>
<script src="react/react-dom.js"></script>
<script src="react/babel.js"></script>
<script type="text/babel"></script>
</body>
<script type="text/babel">
const { useState } = React;
let nextId = 0;
function List() {
const [name, setName] = useState("");
const [artists, setArtists] = useState([]);
return (
<div>
<h1>Inspiring sculptors:</h1>
<input value={name} onChange={(e) => setName(e.target.value)} />
<button
onClick={() => {
setName("");
setArtists([...artists, { id: nextId++, name: name }]);
// artists.push({
// id: nextId++,
// name: name,
// });
}}
>
Add
</button>
<ul>
{artists.map((artist) => (
<li key={artist.id}>{artist.name}</li>
))}
</ul>
</div>
);
}
ReactDOM.render(<List />, document.getElementById("app"));
</script>
</html>