forked from dwyl/learn-react
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
95 lines (79 loc) · 2.22 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-9>
<title>First Component</title>
<link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<!-- container node -->
<div id="app"></div>
<script src="http://fb.me/react-0.12.2.js"></script>
<script src="http://fb.me/JSXTransformer-0.12.2.js"></script>
<script type="text/jsx">
/** @jsx React.DOM */
var MessageBox = React.createClass({
handleAdd: function(e){
console.log(this);
var newMessage = this.refs.newMessage.getDOMNode().value;
var newMessages = this.state.messages.concat([newMessage]);
this.setState({
messages: newMessages
});
},
getInitialState: function() {
return {
isVisible: true,
messages: [
'I like the world',
'Coffee flavored ice cream is highly underrated',
'My spoon is too big',
'Tuesday is coming. Did you bring your coat?',
'I am a banana'
]
}
},
render: function() {
var inlineStyles = {
display: this.state.isVisible ? 'block' : 'none'
};
var messages = this.state.messages.map(function(message) {
return <SubMessage message={message} />
})
return (
<div className="container jumbotron" style={inlineStyles}>
<h2>Hello, World</h2>
<input ref="newMessage" type="text" />
<button className="btn btn-primary" onClick={this.handleAdd}>Add</button>
{ messages }
</div>
);
}
});
var SubMessage = React.createClass({
handleDelete: function(e) {
},
propTypes: function() {
message: React.PropTypes.string.isRequired
},
getDefaultProps: function () {
return {
message: "Its good to see you"
}
},
render: function() {
return (
<div>{this.props.message}</div>
)
}
});
var reactComponent = React.render(
<MessageBox />,
document.getElementById('app'),
function after() {
console.log('hai after render!');
}
)
</script>
</body>
</html>