Skip to content

Commit f123760

Browse files
committed
Completed through hook up data model
1 parent 6e6ff3a commit f123760

File tree

2 files changed

+75
-4
lines changed

2 files changed

+75
-4
lines changed

comments.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,10 @@
88
"id": 1420070400000,
99
"author": "Paul O’Shannessy",
1010
"text": "React is *great*!"
11+
},
12+
{
13+
"id": 1452484385530,
14+
"author": "Sara Falkoff",
15+
"text": "Let's go!"
1116
}
12-
]
17+
]

public/index.html

Lines changed: 69 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,76 @@
1313
</head>
1414
<body>
1515
<div id="content"></div>
16-
<script type="text/babel" src="scripts/example.js"></script>
1716
<script type="text/babel">
18-
// To get started with this tutorial running your own code, simply remove
19-
// the script tag loading scripts/example.js and start writing code here.
17+
18+
var data = [
19+
{id: 1, author: "Pete Hunt", text: "This is one comment"},
20+
{id: 2, author: "Jordan Walke", text: "This is *another* comment"}
21+
];
22+
23+
var CommentBox = React.createClass({
24+
render: function() {
25+
return (
26+
<div className="commentBox">
27+
<h1>Comments</h1>
28+
<CommentList data={this.props.data} />
29+
<CommentForm />
30+
</div>
31+
);
32+
}
33+
});
34+
35+
var CommentList = React.createClass({
36+
render: function() {
37+
var commentNodes = this.props.data.map(function(comment) {
38+
return (
39+
<Comment author={comment.author} key={comment.id}>
40+
{comment.text}
41+
</Comment>
42+
);
43+
});
44+
45+
return (
46+
<div className="commentList">
47+
{commentNodes}
48+
</div>
49+
);
50+
}
51+
});
52+
53+
var CommentForm = React.createClass({
54+
render: function() {
55+
return (
56+
<div className="commentForm">
57+
Hello, world! I am a CommentForm.
58+
</div>
59+
);
60+
}
61+
});
62+
63+
var Comment = React.createClass({
64+
rawMarkup: function() {
65+
var rawMarkup = marked(this.props.children.toString(), {sanitize: true});
66+
return { __html: rawMarkup };
67+
},
68+
69+
render: function() {
70+
return (
71+
<div className="comment">
72+
<h2 className="commentAuthor">
73+
{this.props.author}
74+
</h2>
75+
<span dangerouslySetInnerHTML={this.rawMarkup()} />
76+
</div>
77+
);
78+
}
79+
});
80+
81+
ReactDOM.render(
82+
<CommentBox data={data} />,
83+
document.getElementById('content')
84+
);
85+
2086
</script>
2187
</body>
2288
</html>

0 commit comments

Comments
 (0)