Reactjs 套接字io客户端包上的连接(请求)过多
我使用“socket.io客户端”:“2.2.0”,即package.json上的socket io客户端版本Reactjs 套接字io客户端包上的连接(请求)过多,reactjs,Reactjs,我使用“socket.io客户端”:“2.2.0”,即package.json上的socket io客户端版本 import io from "socket.io-client"; useEffect(() => { let socket = io(socketUrl()); //here goes the url socket.on('connect', () => { socket.emit('authentication',
import io from "socket.io-client";
useEffect(() => {
let socket = io(socketUrl()); //here goes the url
socket.on('connect', () => {
socket.emit('authentication',
{token: localStorage.getItem(`Bearer`), user_id: 0})
});
socket.on("connect_error", (err) => {
console.log(`connect_error due to ${err.message}`);
});
socket.on('authenticated', (obj) => {
socket.emit('start_marking', {token: localStorage.getItem(`Bearer`)});
});
socket.on('mark_payload', data => {
//some functions to manipulate data....
});
socket.on('unauthorized', err =>
console.log("There was an error with the authentication:", err.message));
},[])
这里的问题是什么,所以我得到了这些问题