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

230
Visualizações
How can I receive the ID of the user, and save it as a variable

I have the following code, where I get all the user information from a server:

Promise.all([api.getUserInfo(), api.getCards()])
  .then(([userInf, cards]) => {
    userInfo.setUserInfo({
      name: userInf.name,
      job: userInf.about,
      id: userInf._id,
    });
    userInfo.setUserAvatar({
      avatar: userInf.avatar,
    });
    cardsList.renderItems(cards);
  })
  .catch((err) => console.log(err));

I want to save the userId, (which is above as userInf._id), as a constant outside the function, so I can use it seperately to create cards. But directly writing something like const userId = userInf._id can't be used outside the function. Also trying to create a setUserId and getUserId method like this:

  setUserId({ id }) {
    this._userID = id;
  }

  getUserId() {
    return this._userID;
  }

in the userinfo class does not work since getUserId returns undefined.

about 4 years ago · Juan Pablo Isaza
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