|
13 | 13 | </head>
|
14 | 14 | <body>
|
15 | 15 | <div id="content"></div>
|
16 |
| - <script type="text/babel" src="scripts/example.js"></script> |
17 | 16 | <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 | + |
20 | 86 | </script>
|
21 | 87 | </body>
|
22 | 88 | </html>
|
0 commit comments