Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

147
Views
await Asyncstorage returns a promise

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
};
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

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."

about 4 years ago · Juan Pablo Isaza Report

0

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")    
};
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!