我想連接到coincap.io
public socket.io
API。我已經設置了一切,但不知道在我的組件的哪個位置放置了socket.io
代碼。它是否在constructor
或componentWillMount
或哪裏?它是socket.io
,所以它顯然總是需要打開,所以在一個組件將去哪裏?這是我需要的地方注入到我的組件代碼:將socket.io代碼放在組件中的位置?
this.socket = io.connect('http://socket.coincap.io');
this.socket.on('connect', function(tradeMsg) {
console.log("It worked");
});
好的謝謝。問題是,它的socket.io不是一個正常的api請求,所以如果它只在componentDidMount()中調用1次,那麼連接仍然是如何打開和監聽? – PurplePanda