Created
January 18, 2016 16:22
-
-
Save wontwon/f977a209faf00771ddcc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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