简体   繁体   中英

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

In my React Native app I want to re-render my component in a fixed time again and again after each three seconds. But it only gets called once. How can I get it called multiple times for that limited time frame. Here's my present code:

  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); } }); } 

Any help would be appreciated.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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