所以我试图有条件地渲染我的抽屉菜单。我有这个显示组件
const Display = () => {
const getData = async () => {
try {
const value = await AsyncStorage.getItem('loggedIn');
if (value !== null) {
let check4Login = value === 'true';
if (check4Login === true) {
console.log('logged in user ');
return (
<NavigationContainer>
<Drawer.Navigator initialRouteName="Home">
<Drawer.Screen name="Home" component={HomeArea} />
<Drawer.Screen name="Login" component={LoginPage} />
<Drawer.Screen name="User Dashboard" component={MyAccount} />
<Drawer.Screen name="Settings" component={Settings} />
<Drawer.Screen name="Logout" component={Logout} />
</Drawer.Navigator>
<StatusBar barStyle="dark-content" />
</NavigationContainer>
);
} else {
console.log('logged out user ');
return (
<NavigationContainer>
<Drawer.Navigator initialRouteName="Home">
<Drawer.Screen name="Home" component={HomeArea} />
<Drawer.Screen name="Login" component={LoginPage} />
<Drawer.Screen name="User Dashboard" component={MyAccount} />
<Drawer.Screen name="Settings" component={Settings} />
<Drawer.Screen name="Logout" component={Logout} />
</Drawer.Navigator>
<StatusBar barStyle="dark-content" />
</NavigationContainer>
);
}
}
} catch (e) {
// error reading value
}
};
getData();
};
在此组件中,我正在检查用户当前是否已登录,如果用户已登录,则我将返回正确的抽屉菜单。
然后我要调用显示组件
const App = () => {
checkLogin();
return <Display />;
};
此处显示。但是由于某种原因,我得到了错误“渲染没有返回任何结果”,即使代码正以应有的方式返回到返回值。例如,现在我得到console.log“已登录用户”,但似乎看不到我所假定的返回值,因此出现了错误。难道我做错了什么?非常感谢任何建议,非常感谢=]