Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

229
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda