So I am trying to conditionally render my drawer menu. I have this display component
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();
};
and in this component I am checking for if the user is currently logged in, then if the user is logged in, I am returning the proper drawer menu.
Then I am calling the display component
const App = () => {
checkLogin();
return <Display />;
};
here to be displayed. But for some reason I am getting the error "Nothing was returned from render" even tho the code is getting to the returns like it should. For example right now I get the console.log "logged in user", but it does not seem to see the return I am assuming hence the error. Am I doing something wrong? Would appreciate any suggestions, thanks so much =]