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

143
Visualizações
How to get value from object property in React or Javascript

Why do I have to wrap await with () in order to get the output I need. I am hoping to get only the uid from the object

The data that is return from the function that I am importing is exactly how you see it

{uid : 'abcdefg', email:'youremail@gmail.com'}
import {ActiveUser} from './teamMembers.service';

export const retrieveList = async date => {
console.log('active user information here', (await ActiveUser()).uid); 
// outputs: Works as expected
// active user information here abcdefg

console.log('active user information here', await ActiveUser().uid); 
// outputs: 
//Undefined

console.log('active user information here', typeof (await ActiveUser()));
// outputs: 
// object
}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

The await operator is used to wait for a Promise (The Promise object represents the eventual completion (or failure) of an asynchronous operation and its resulting value) and it can only be used inside an async function.

You need to await you're async task (ActiveUser) once and after that you can just reference it's data (which is the resolved state of that async code happening there)

import {ActiveUser} from './teamMembers.service';

export const retrieveList = async date => {
   const data = await ActiveUser();
   const uid = data.uid;
   const name = data.name;
}

I suggest you read more The event loop and the concurrency model and it's secret behind the JavaScript's asynchronous programming.

More about async - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function

More about event loop - https://developer.mozilla.org/en-US/docs/Web/JavaScript/EventLoop

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