Skip to content

Instantly share code, notes, and snippets.

@wontwon
Created January 18, 2016 16:22
Show Gist options
  • Save wontwon/f977a209faf00771ddcc to your computer and use it in GitHub Desktop.
Save wontwon/f977a209faf00771ddcc to your computer and use it in GitHub Desktop.
import React from 'react';
import ChatLine from './chat-line';
const ChatLog = React.createClass({
getInitialState: function() {
console.log('initial state');
return { lines: [] };
},
addMessage: function(msg) {
console.log('add message');
msg.id = this.state.lines.length;
this.state.lines.push(msg);
this.render();
console.log(this.state);
},
render: function() {
console.log(this.state);
var chatLine = this.state.lines.map(function(line) {
<ChatLine key={line.id} user={line.user} msg={line.msg} />
});
return (
<div>
{chatLine}
</div>
);
}
});
export default ChatLog;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment