繁体   English   中英

将setInterval设置为多次调用,但在本机反应中仅被调用一次

[英]Setting setInterval to call multiple times but gets only called once in react native

在我的React Native应用中,我想每隔三秒钟一次又一次地固定时间重新渲染我的组件。 但是它只被调用一次。 我如何才能在有限的时间内多次调用它。 这是我目前的代码:

  refreshData = async()=> { await fetch('https://myapi', { method: 'GET', }) .then((response) => response.json()) .then((response) => { this.setState({ tableData1: response.First }) this.setState({ tableData2: response.Special }) this.setState({ tableData3: response.Consolidation }) }) } componentWillMount() { const { navigation } = this.props; this.focusListener = navigation.addListener("didFocus", () => { var today = new Date() var time = today.getHours() console.log(today.getMinutes()) var weekDay = today.getDay() if ((time >= 22) && (time <= 23 )){ if(today.getMinutes()<=30){ setInterval(()=> { this.refreshData() }, 3000); } }); } 

任何帮助,将不胜感激。

如果使用远程JS调试进行调试,建议您停止JS调试,然后尝试执行该代码,因为这是一个已知问题,例如setTimeout和setInterval在“远程JS调试”模式下无法正常运行,请查看是否有区别。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM