title: Redux-thunk with Websockets
body: <p>I want to create a websocket on demand when certain components want to subscribe to data. How can I share the websocket instance in a redux fashion?</p>
  
  <p>action.js</p>
  
  <pre><code>export function subscribeToWS(url) {
     return dispatch =&gt; {
        let websocket = new WebSocket(url)
        websocket.on('connect', () =&gt; {
           websocket.send("subscribe") 
        }
        websocket.on('message', (message) =&gt; {
          dispatch(storeNewData(message))
        }
     } 
  }
  </code></pre>
  
  <p>I could do something like this, but this would require a new instance for every new subscription.</p>