Reputation: 2528
componentDidMount(){
console.log("get")
AsyncStorage.getItem('token')
.then((res)=>{
console.log(res)
})
}
I have componentDidMount with console.log and AsyncStorage.getItem function.I want to make axios call after getting the token value.
But the thing is AsyncStorage.getItem is not working get //console.log('get')
is printed as log without res.
Any help please how to get value? am I doing something wrong?
Upvotes: 0
Views: 137
Reputation: 2528
Try to Just restart the app and asyncStorage will behave properly.
Upvotes: 0
Reputation: 737
You can do it as follows.
componentDidMount(){
this.onGetToken();
}
onGetToken = async () => {
try {
const token = await AsyncStorage.getItem('token');
console.log("get")
// call api using axios with token value
} catch(e => console.info('error for getting token', e))
}
Upvotes: 2