在我的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);
}
});
}
任何帮助将不胜感激。
答案 0 :(得分:0)
如果您正在使用远程JS调试进行调试,我建议您尝试在JS调试停止的情况下尝试代码,因为这是已知问题,例如setTimeout和setInterval在远程JS调试模式下无法正常运行,请查看是否有区别