File tree Expand file tree Collapse file tree 1 file changed +26
-7
lines changed Expand file tree Collapse file tree 1 file changed +26
-7
lines changed Original file line number Diff line number Diff line change 1
- class Comment extends React.Component{
1
+ const data = [
2
+ {id: 1, author: "Pete Hunt", text: "This is one comment"},
3
+ {id: 2, author: "Jordan Walke", text: "This is *another* comment"}
4
+ ];
5
+
6
+ class Comment extends React.Component {
2
7
constructor(props) {
3
8
super(props);
4
9
}
5
10
11
+ rawMarkup() {
12
+ let md = new Remarkable();
13
+ let rawMarkup = md.render(this.props.children.toString());
14
+ return {__html: rawMarkup};
15
+ }
16
+
6
17
render() {
18
+ // let md = new Remarkable();
7
19
return (
8
20
<div className="comment">
9
21
<h2 className="commentAuthor">
10
22
{this.props.author}
11
23
</h2>
12
- {this.props.children}
24
+ <span dangerouslySetInnerHTML= {this.rawMarkup()}/>
13
25
</div>
14
26
);
15
27
}
@@ -21,9 +33,18 @@ class CommentList extends React.Component {
21
33
}
22
34
23
35
render() {
36
+ let commentNodes = this.props.data.map(function (comment) {
37
+ return (
38
+ <Comment author={comment.author} key={comment.id}>
39
+ {comment.text}
40
+ </Comment>
41
+ )
42
+ });
43
+
44
+
24
45
return (
25
46
<div className="commentList">
26
- Hello, world! I am a CommentList.
47
+ {commentNodes}
27
48
</div>
28
49
);
29
50
}
@@ -52,16 +73,14 @@ class CommentBox extends React.Component {
52
73
return (
53
74
<div className="commentBox">
54
75
<h1>Comments</h1>
55
- <CommentList/>
76
+ <CommentList data={this.props.data} />
56
77
<CommentFrom/>
57
78
</div>
58
79
);
59
80
}
60
81
}
61
82
62
-
63
-
64
83
ReactDOM.render(
65
- <CommentBox />,
84
+ <CommentBox data={data} />,
66
85
document.getElementById('content')
67
86
);
You can’t perform that action at this time.
0 commit comments