forked from akhilpandey95/bucket
-
Notifications
You must be signed in to change notification settings - Fork 0
/
comp2.js
68 lines (60 loc) · 1.62 KB
/
comp2.js
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
61
62
63
64
65
66
67
68
var Stuff = React.createClass({
render: function() {
return (
<div>
<img src="{this.props.image}" />
<h3> {this.props.thing.url}</h3>
<span> {this.props.thing.meta} </span>
</div>
);
}
});
var inputForm = React.createClass({
handleSubmit: function(e) {
e.preventDefault();
var content = React.findDOMNode(this.refs.content).value.trim();
this.props.onCommentSubmit({content: content});
React.findDOMNode(this.refs.content).value = '';
},
render: function() {
return (
<form className="commentForm" onSubmit={this.handleSubmit}>
<input type="text" placeholder="A link to bundle" ref="content" />
<input type="submit" value="Add to bundle" />
</form>
);
}
});
var StuffList = React.createClass({
render: function() {
var rows = [];
var things = this.props.data;
things.forEach(function(item) {
rows.push(<Stuff thing={item} />);
});
return (
<div>
{rows}
</div>
);
}
});
var StuffDisplay = React.createClass({
handleCommentSubmit: function(comment) {
var comments = this.state.data;
comments.push(comment);
},
getInitialState: function() {
return {data: []};
},
render: function() {
return (
<div className="commentBox">
<h1>Comments</h1>
<StuffList data={this.state.data} />
<inputForm onCommentSubmit={this.handleCommentSubmit} />
</div>
);
}
});
React.render(<StuffDisplay /> ,document.getElementById('testid'));