-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathblog-comments.htm
More file actions
78 lines (69 loc) · 1.76 KB
/
Copy pathblog-comments.htm
File metadata and controls
78 lines (69 loc) · 1.76 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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>React Blog Comments</title>
</head>
<body>
<div id="root"></div>
<script src="https://unpkg.com/react@15/dist/react.js"></script>
<script src="https://unpkg.com/react-dom@15/dist/react-dom.js"></script>
<script src="https://fb.me/JSXTransformer-0.13.3.js"></script>
<style>
.Comment {
margin-bottom: 40px;
}
</style>
<script type="text/jsx">
function Avatar(props) {
return (
<img className="Avatar"
src={'https://api.adorable.io/avatars/80/' + props.user.username}
alt={props.user.username}
/>
);
}
function UserInfo(props) {
return (
<div className="UserInfo">
<Avatar user={props.user} />
<div className="UserInfo-name">
{props.user.username}
</div>
</div>
);
}
// Having Avatar and UserInfo as separate components enables reuse later.
// And it can allow us to rearrange them into a different layout more easily.
function Comment(props) {
return (
<div className="Comment">
<UserInfo user={props.author} />
<div className="Comment-text">
{props.text}
</div>
<div className="Comment-date">
{props.date}
</div>
</div>
);
}
function Blog() {
let dilip = {username: "Dilip"};
let sarah = {username: "Sarah"};
let fred = {username: "Fred"};
return (
<div>
<Comment author={dilip} text="Hello, this is a comment." date="12 May, 2014"/>
<Comment author={sarah} text="Hello, this is a reply." date="14 Aug, 2015"/>
<Comment author={fred} text="I don't understand this. Could you explain?" date="25 Oct, 2016"/>
</div>
);
}
ReactDOM.render(
<Blog />,
document.getElementById('root')
);
</script>
</body>
</html>