title: socket io event fires multiple times
body: <p>I have searched similar questions here but none of them work for me. </p>
  
  <p>I know some people recommend not to use socket inside another event but I had no clue how to trigger socket whenever there is an event.</p>
  
  <p>So I have initialized socket inside another event which is updated every time something happens. But socket connection repeats the previous result with every new update. </p>
  
  <p>I tried initializing socket within componentDidMount lifecyle and it simply does not work.</p>
  
  <pre><code>class UploadComponent extends Component {
    constructor (props) {
      super(props);
  
      this.state = {
        endpoint: "http://localhost:3000",
      }
  
      this.uploadModal = this.uploadModal.bind(this);
    }
  
    uploadModal () {
  
       update.on('success', file =&gt; {
            let {endpoint} = this.state;
            let socket = socketIOClient(endpoint, {transports: ['websocket', 'polling', 'flashsocket']});
  
            socket.on('data', (mydata) =&gt; {
              console.log(mydata) // &lt;-- This gets fired multiple times.
            })
        })
  
     }
  
  // some more code //
  }
  </code></pre>
  
  <p>I want to trigger socket whenever "update" event is fired without message duplication.</p>