-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path10.jsx.children&fragment.html
64 lines (60 loc) · 1.65 KB
/
10.jsx.children&fragment.html
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
<!DOCTYPE html>
<html>
<head>
<title>Multiple children</title>
<meta charset="utf-8" />
<style>
body {
font-family: -apple-system, sans-serif;
}
</style>
</head>
<body>
<div id="app1"></div>
<div id="app2"></div>
<div id="app3"></div>
<div id="app4"></div>
<script src="react/react.js"></script>
<script src="react/react-dom.js"></script>
<script src="react/babel.js"></script>
<script type="text/babel">
function Example() {
return (
<div>
<span>Hello</span> <span>World</span>
</div>
);
}
function FragmentExample() {
// todo(lin): need babel >= 7.0
// return (
// <>
// <span>Hello</span> <span>World</span>
// </>
// );
return (
<React.Fragment>
<span>Hello</span> <span>World</span>
</React.Fragment>
);
}
function ArrayExample() {
return [<span key="a">Hello</span>, " ", <span key="b">World</span>, "!"];
}
function ChildrenExample(props) {
console.log(props.children.length);
debugger;
return <div>{props.children}</div>;
}
ReactDOM.render(<Example />, document.getElementById("app1"));
ReactDOM.render(<FragmentExample />, document.getElementById("app2"));
ReactDOM.render(<ArrayExample />, document.getElementById("app3"));
ReactDOM.render(
<ChildrenExample>
<span key="greet">Hello</span> <span key="world">World</span>!
</ChildrenExample>,
document.getElementById("app4")
);
</script>
</body>
</html>