title: Add message to chat component(react.js) via websockets
body: <p><strong>Context:</strong></p>
  
  <p>I am developing a Ruby On Rails application and I started using React.js to manage my javascript components.
  My application provides a facebook-like chat: several chats are displayed at the bottom of the page.</p>
  
  <p><strong>Problem</strong></p>
  
  <p>I have a ChatList component that renders the chats. A chat is made of its messages and its form. When this form is submitted, an AJAX call is made to the server to POST the message and the message is added to the current chat.</p>
  
  <pre class="lang-js prettyprint-override"><code>this.setState({messages: this.state.messages.concat([newMessage])});
  </code></pre>
  
  <p>The server then broadcast Javascript code to the receiver.</p>
  
  <p>This is where I'm stuck. How can I add the message to the correct chat? How can I select my React.js component and change its 'props'?
  When I was not using react, I used to broadcast this code to the other user:</p>
  
  <pre class="lang-js prettyprint-override"><code>$("#chat-&lt;%= chat.id %&gt;").append("&lt;%= message.content" %&gt;);
  </code></pre>
  
  <p>I guess I have to find a way to select the React component (the chat instance) and change its property "messages". How?</p>
  
  <p>Thank you for your help! :)</p>
  
  <p>EDIT: I'm going to add more information, just in case:</p>
  
  <ul>
  <li>My ChatList is a global variable that takes an array of Chats. </li>
  <li>Each Chat takes an array of Message and a form.</li>
  </ul>
  
  <p>When I submit the form of a chat, it adds the message to the Chat (locally and it also posts the new message to the server). When the server receives the POST event, it can render javascript code to the other user. </p>
  
  <p>This code should add the message to the correct Chat for the correct user. There are two pieces missing:</p>
  
  <ol>
  <li>I don't know how I can "select" the Chat.</li>
  <li>I don't know how I can add a message to the "messages" array of this Chat.</li>
  </ol>