【发布时间】:2021-04-28 08:36:06
【问题描述】:
我需要根据 react-native 导航中的 AsyncStorage 值进行导航。但即使我在 AsyncStorage 中有值,它也总是将我带到登录页面。
低于我目前所尝试的,
function App(props) {
const [storeId, setStoreId] = useState(null);
AsyncStorage.getItem(STORAGE_KEYS.LOCATION_ID).then((id) => {
setStoreId(id);
});
const initialRoute = storeId && 'NfcScreen';
return (
<Provider store={store}>
<NavigationContainer>
<Stack.Navigator
initialRouteName={initialRoute}
screenOptions={!isTablet ? styles : ''}>
{isTablet && (
<Stack.Screen
options={{headerShown: false}}
name={appPages.locationIdentification}
component={Locationidentification}
/>
)}
<Stack.Screen
name={appPages.nfc}
component={NfcPage}
options={{headerShown: false}}
/>
</Stack.Navigator>
</NavigationContainer>
</Provider>
我注意到第一个状态返回 null 然后它返回 asyncstorage 值。因为状态更新缓慢,所以 locationIdentification 页面会被渲染。有什么办法可以试试吗?
帮助将非常明显。谢谢:)
【问题讨论】:
标签: react-native react-native-android react-native-navigation