title: How to set socket response to react state
body: <p>Whenever socket receive new data i am trying to set this data to state.<br>
   I am creating simple chat application and i want to set this recent chat data received from socket set to state.</p>
  
  <pre><code>    var socket = constants.SERVER;  
      var chatData = ""
  
      class Chat extends Component {
  
          constructor(props) {
              super(props);
              this.state = { recentChat:[] }
          }
  
  
    componentDidUpdate()
    {
      socket.on(constants.SOCKET_GET_CHAT, function(data){
        console.log(JSON.stringify(data))
  
            this.setState({
            recentChat:data
         })
      });
  
    }
  
          render() {
              return(&lt;div/&gt;)   
          }
      }
  </code></pre>