Skip to content

Instantly share code, notes, and snippets.

@wontwon
Created January 18, 2016 16:22
Show Gist options
  • Select an option

  • Save wontwon/f977a209faf00771ddcc to your computer and use it in GitHub Desktop.

Select an option

Save wontwon/f977a209faf00771ddcc to your computer and use it in GitHub Desktop.

Revisions

  1. wontwon created this gist Jan 18, 2016.
    33 changes: 33 additions & 0 deletions ughh.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,33 @@
    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;