-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
61 lines (60 loc) · 1.95 KB
/
index.html
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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>React Tutorial</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.2.1/react.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.2.1/react-dom.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.34/browser.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/remarkable/1.6.2/remarkable.min.js"></script>
</head>
<body>
<div id="content"></div>
<script type="text/babel">
var CommentList = React.createClass({
render: function() {
return (
<div className="commentList">
{ this.props.comments.map((comment, index) => <div key={index}><p>{ comment }</p></div>) }
</div>
);
}
});
var CommentBox = React.createClass({
getInitialState: function() {
return {
comments: []
};
},
addComment: function() {
this.setState({
comments: this.state.comments.concat(this.refs.commentBody.value)
});
this.refs.commentBody.value = '';
},
clearComments: function() {
this.setState({
comments: []
});
},
render: function() {
return (
<div className="commentBox">
<h1>Comments</h1>
<CommentList comments={this.state.comments} />
<input type="text" ref="commentBody" />
<button onClick={this.addComment}>Add comment</button>
<br/>
<button onClick={this.clearComments}>Clear comments</button>
</div>
);
}
});
ReactDOM.render(
<CommentBox />,
document.getElementById('content')
);
</script>
</body>
</html>