[英]clearInterval() won't clear setInterval and Affect navigation
好了,所以我有一個使用setInterval
的啟動屏幕,但問題是setInterval
現在基本上影響了我嘗試使用clearInterval
應用程序中的整個導航,但是它不起作用。
我試着從改變componentWillMount
到componentDidMount
,但它仍然無法正常工作。
componentDidMount(){
const splashInterval = setInterval(()=>{
this.props.navigation.navigate('Main');
},2000);
this.setState({splashInterval: splashInterval});
}
componenWillUnmount(){
const splashInterval = this.state.splashInterval;
const clearSplashInterval = this.props.navigation.clearInterval(splashInterval);
this.setState(clearSplashInterval);
}
您不需要清除間隔,您只需
componentDidMount(){
setTimeout(() => {
this.props.navigation.navigate("Main")
}, 100);
}
當您導航到另一個類時,可以使用它,並且如果您想像不希望啟動屏幕那樣在堆棧中重設堆棧
componentDidMount(){
setTimeout(() => {
const resetAction = StackActions.reset({
index: 0,
actions: [NavigationActions.navigate({ routeName: 'main' })],
});
this.props.navigation.dispatch(resetAction);
}, 100);
}
為什么從道具中獲得clearInterval?
清除setInterval
做這個
componentDidMount(){
this.inter = setInterval(async() => {
this.props.navigation.navigate('Main');
}, 2000);
}
componenWillUnmount(){
clearInterval(this.inter);
}
clearInterval()函數清除之前由setInterval()函數設置的間隔。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.