Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/react-native/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
React native 检查react native上的新消息_React Native_Setinterval - Fatal编程技术网

React native 检查react native上的新消息

React native 检查react native上的新消息,react-native,setinterval,React Native,Setinterval,我正在做一个本地聊天应用程序。我在聊天屏幕上获取其他用户的消息时遇到问题 this.intervalID = setInterval(() => { this.setState({ count: this.state.count + 1 }); }, 1000); 目前,我每秒都有一个setInterval来检查新消息,但这会使应用程序运行得非常慢,服务器也会受到影响 有更好的方法吗 谢谢与其每秒检查一次新邮件,不如使用另一个web套接字服务而不是轮

我正在做一个本地聊天应用程序。我在聊天屏幕上获取其他用户的消息时遇到问题

this.intervalID = setInterval(() => {               
  this.setState({ count: this.state.count + 1 });  
}, 1000);
目前,我每秒都有一个setInterval来检查新消息,但这会使应用程序运行得非常慢,服务器也会受到影响

有更好的方法吗


谢谢

与其每秒检查一次新邮件,不如使用另一个web套接字服务

而不是轮询新邮件,不如使用例如WebSockets。