-
Notifications
You must be signed in to change notification settings - Fork 0
/
message.jsx
35 lines (32 loc) · 955 Bytes
/
message.jsx
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
const React = require('react'),
ReactDOM = require('react-dom');
const Message = React.createClass({
getInitialState: function() {
return {
inputValue: ''
};
},
onChange: function(e) {
this.setState({inputValue: e.target.value});
},
onSubmit: function(e) {
e.preventDefault();
this.props.addMessage(this.props.username, this.state.inputValue);
this.setState({inputValue: ''});
},
render: function() {
return (
<div>
<form onSubmit={this.onSubmit}>
<input value={this.state.inputValue} onChange={this.onChange} />
</form>
{
this.props.message.map(function(elem, ind) {
return <p key={ind}>{elem.user}: {elem.text}</p>;
})
}
</div>
);
}
});
module.exports = Message;