在 navigation.goback() 之后需要 return?
need return after navigation.goback()?
使用 React Navigation 5.x,是否应在下面的代码片段中的 navigation.goBack() 之后使用 return?
if (condition_met) {
setTimeout(()=> {
navigation.goBack();
return; //<<==needed after navigation or useless/never executed?
}, 1000);
}
//do something else if above condition not met.
setTimeout
调用的函数在// do something else
之后执行。
将 return
语句移到 setTimeout
之外
if (condition_met) {
setTimeout(()=> {
navigation.goBack();
}, 1000);
return; //condition met stop executing code further
}
//do something else if above condition not met.
通常建议在关闭组件时调用的 useEffect 的 return 函数中处理此类效果。
useEffect(() => {
return () => {
// cleanup code codes here
};
},[]);
这将在 navigation.goBack()
关闭屏幕组件后起作用。
使用 React Navigation 5.x,是否应在下面的代码片段中的 navigation.goBack() 之后使用 return?
if (condition_met) {
setTimeout(()=> {
navigation.goBack();
return; //<<==needed after navigation or useless/never executed?
}, 1000);
}
//do something else if above condition not met.
setTimeout
调用的函数在// do something else
之后执行。
将 return
语句移到 setTimeout
if (condition_met) {
setTimeout(()=> {
navigation.goBack();
}, 1000);
return; //condition met stop executing code further
}
//do something else if above condition not met.
通常建议在关闭组件时调用的 useEffect 的 return 函数中处理此类效果。
useEffect(() => {
return () => {
// cleanup code codes here
};
},[]);
这将在 navigation.goBack()
关闭屏幕组件后起作用。