Skip to content

Commit 470c945

Browse files
author
Matt Calthrop
committed
Add tutorial8-10
1 parent 414fec8 commit 470c945

File tree

2 files changed

+71
-1
lines changed

2 files changed

+71
-1
lines changed

public/index.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
<!--<script type="text/babel" src="scripts/tutorial1.js"></script>-->
1818
<!--<script type="text/babel" src="scripts/tutorial2-3.js"></script>-->
1919
<!--<script type="text/babel" src="scripts/tutorial4-5.js"></script>-->
20-
<script type="text/babel" src="scripts/tutorial6-7.js"></script>
20+
<!--<script type="text/babel" src="scripts/tutorial6-7.js"></script>-->
21+
<script type="text/babel" src="scripts/tutorial8-10.js"></script>
2122
</body>
2223
</html>

public/scripts/tutorial8-10.js

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/* global React, ReactDOM */
2+
3+
var data = [
4+
{id: 1, author: "Neil Peart", text: "Hemispheres"},
5+
{id: 2, author: "Neil Fallon", text: 'Blast Tyrant'}
6+
];
7+
8+
var Comment = React.createClass({
9+
rawMarkup: function () {
10+
var rawMarkup = marked(this.props.children.toString(), {sanitize: true});
11+
12+
return {__html: rawMarkup};
13+
},
14+
render: function () {
15+
return (
16+
<div className="comment">
17+
<h2 className="commentAuthor">
18+
{this.props.author}
19+
</h2>
20+
<span dangerouslySetInnerHTML={this.rawMarkup()}/>
21+
</div>
22+
);
23+
}
24+
});
25+
26+
var CommentList = React.createClass({
27+
render: function () {
28+
var commentNodes = this.props.data.map(function (comment) {
29+
return (
30+
<Comment key={comment.id} author={comment.author}>
31+
{comment.text}
32+
</Comment>
33+
);
34+
});
35+
36+
return (
37+
<div className="commentList">
38+
{commentNodes}
39+
</div>
40+
);
41+
}
42+
});
43+
44+
var CommentForm = React.createClass({
45+
render: function () {
46+
return (
47+
<div className="commentForm">
48+
Hello, world! I am a CommentForm.
49+
</div>
50+
);
51+
}
52+
});
53+
54+
var CommentBox = React.createClass({
55+
render: function () {
56+
return (
57+
<div className="commentBox">
58+
<h1>Comments</h1>
59+
<CommentList data={this.props.data}/>
60+
<CommentForm />
61+
</div>
62+
);
63+
}
64+
});
65+
66+
ReactDOM.render(
67+
<CommentBox data={data}/>,
68+
document.getElementById('content')
69+
);

0 commit comments

Comments
 (0)