Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

134
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda