使用钩子 INVALID_STATE_ERR 反应原生 websockets

时间:2021-04-04 13:48:38

标签: react-native websocket

React Native 不会通过 websocket 发送多条状态改变消息。服务器正常接收第一个字符串,客户端在每次状态更改时获取控制台日志。知道为什么我会收到关于状态的错误吗?

useEffect(() => {
    socket.onopen = function (e) {
      socket.send(String(state?.x));

    };
    socket.send("test")  <-- this one does not work 
    console.log("send")
    socket.onmessage = function () {
      console.log("message")
    }

    socket.close();
  }, [state])

返回错误 INVALID_STATE_ERR

0 个答案:

没有答案