簡體   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