-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path13.eventhandler.html
More file actions
44 lines (39 loc) · 1.11 KB
/
13.eventhandler.html
File metadata and controls
44 lines (39 loc) · 1.11 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
<!DOCTYPE html>
<html>
<head>
<title>event handler</title>
<meta charset="utf-8" />
<style>
body {
font-family: -apple-system, sans-serif;
}
</style>
</head>
<body>
<div id="app1"></div>
<div id="app2"></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">
function Button() {
function handleClick() {
alert("You clicked me!");
}
return <button onClick={handleClick}>Click me</button>;
}
function Button2({ onClick, children }) {
return <button onClick={onClick}>{children}</button>;
}
function PlayButton({ movieName }) {
function handlePlayClick() {
alert(`Playing ${movieName}!`);
}
return <Button2 onClick={handlePlayClick}>Play "{movieName}"</Button2>;
}
ReactDOM.render(<Button />, document.getElementById("app1"));
ReactDOM.render(<PlayButton movieName="The Matrix" />, document.getElementById("app2"));
</script>
</html>