Settimer 延迟后只调用一次,但是,它不会在 React Native 中重复调用
Settimer is calling only once after delay, But, It is not repeatedly calling in React Native
我必须在我的 React Native 应用程序中每 10 分钟调用一些 API。所以,我在 ComponentDidMount 方法中定义了定时器和 Setinterval,但是,它只调用一次,而不是重复调用。
componentDidMount() {
this.timer = setInterval(() => this.callAPI(), 600000);
}
callApi = async () => {
//calling some api here
}
有什么建议吗?
最后我通过关注解决了这个问题。
setInterval(() => this. callAPI(), 600000);
以上方法每10分钟延迟调用一次。
希望这对以后的人有所帮助。
我必须在我的 React Native 应用程序中每 10 分钟调用一些 API。所以,我在 ComponentDidMount 方法中定义了定时器和 Setinterval,但是,它只调用一次,而不是重复调用。
componentDidMount() {
this.timer = setInterval(() => this.callAPI(), 600000);
}
callApi = async () => {
//calling some api here
}
有什么建议吗?
最后我通过关注解决了这个问题。
setInterval(() => this. callAPI(), 600000);
以上方法每10分钟延迟调用一次。 希望这对以后的人有所帮助。