React native 使用钩子反应本机WebSocket无效\u状态\u错误
React Native不会通过websocket发送状态更改的多条消息。服务器正常接收第一个字符串,客户端在每次状态更改时获取控制台日志。知道我为什么会在状态上出错吗React native 使用钩子反应本机WebSocket无效\u状态\u错误,react-native,websocket,React Native,Websocket,React Native不会通过websocket发送状态更改的多条消息。服务器正常接收第一个字符串,客户端在每次状态更改时获取控制台日志。知道我为什么会在状态上出错吗 useEffect(() => { socket.onopen = function (e) { socket.send(String(state?.x)); }; socket.send("test") <-- this one does not work
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])
useffect(()=>{
socket.onopen=函数(e){
socket.send(字符串(状态?.x));
};
socket.send(“test”)您正在使用socket.io吗?不,我没有。React native支持websocket。我曾考虑使用socket.io,但在设置时遇到问题。