I am using a helper function to get the token from Asyncstorage and add it to the axios header but instead it gives a promise. My function is like this:
const getToken = async () => {
const token = await AsyncStorage.getItem("token")
return token
};
Here's some information about how to handle promises:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Using_promises https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise
I believe the parameter of the callback that you pass to .then will receive the value that your asynchronous function "returns."
you are awaiting the token, it's supposed to return a promise. the correct way is:
async function getToken() {
return await AsyncStorage.getItem("token");
}
OR
const getToken = async () => {
return await AsyncStorage.getItem("token")
};