-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexamplesInOne.html
More file actions
96 lines (80 loc) · 2.63 KB
/
examplesInOne.html
File metadata and controls
96 lines (80 loc) · 2.63 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.4.2/react.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.4.2/react-dom.min.js"></script>
<!--Need this JSX Transformer to convert to JS-->
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.13.3/JSXTransformer.js"></script>
</head>
<body>
<div id="root"></div>
<div id="clock"></div>
<div id="compo"></div>
<div id='notes'></div>
<script type="text/jsx">
const user = {
firstName: 'Howard',
lastName: 'Chiam',
url: 'https://github.com/hchiam'
};
function formatName(user) {
return user.firstName + ' ' + user.lastName;
}
const htmlStuff = (
<div>
<h1>
Hello, {formatName(user)}!
</h1>
<a href={user.url} target="_blank">{user.url}</a>
</div>
);
ReactDOM.render(
htmlStuff,
document.getElementById('root')
);
/*---------------------------------*/
class Clock extends React.Component {
render() {
return (
<div>
<p><b>Time: {new Date().toLocaleTimeString()}</b></p>
</div>
);
}
}
function clock() {
ReactDOM.render(
<Clock/>,
document.getElementById("clock")
);
}
setInterval(clock, 1000);
/*---------------------------------*/
function ComponentName(propsVar) {
return <p><i>Hey, {propsVar.name}. {propsVar.msg}</i></p>;
}
const element = <ComponentName name="you" msg='This is a Component. Both function and XML-like names must start with a capital letter' />;
ReactDOM.render(
element,
document.getElementById('compo')
);
/*---------------------------------*/
function TemplateNote(info) {
return <li>➜ {info.note}</li>;
}
function Notes() {
return (
<ul>
<TemplateNote note='Use Babel JS preprocessor.'/>
<TemplateNote note='Import react.min.js (see settings).'/>
<TemplateNote note='Import react-dom.min.js (see settings).'/>
</ul>
);
}
ReactDOM.render(
<div>
<h1>Notes:</h1>
<Notes/>
</div>,
document.getElementById('notes')
);
</script>
</body>