0
I’ve been trying for some time to return an item stored in the Asyncstorage of React Active, but the return is always a Promise, but what I want is to make decisions with this return later, and be able to access the value outside the scope of Promise! what I want to do is:
const user = await AsyncStorage.getItem('user')
So you can use the constant user Is it possible afterwards? If it is not possible it is really necessary to encompass all that I wish to do within the Premomise? and what is the alternative for this?
EDIT
The goal of using Asyncstorage here is to recover the logged in user, so I can direct it to home if it is logged in or to login if it is not on the App startup. The idea is to change the initialRouteName. Something like this:
let initialScreen = 'Login'
AsyncStorage.getItem('user').then(user => {
if(user) initialScreen = 'Home'
})
const AppNavigator = createStackNavigator({
Home: {
screen: Home,
navigationOptions: {
title: 'Home',
header: null
},
},
Login: {
screen: Login,
navigationOptions: {
title: 'Login',
header: null
},
}
}, {initialRouteName: initialScreen});
const AppContainer = createAppContainer(AppNavigator)
export default AppContainer
Thank you very much!
the query return is a json string or just a simple string?
– Murilo Medeiros