'How to get data from Firestore in map function

I want to retrieve data from Firestore as I map through an object to see if the user is online. I'm not sure how to retrieve the data.

When I console.log userInLobby (as shown below), I get [Promise] array.

If I try to set a variable before the firebase call, I cannot change the variable inside the .then() function

 const userInLobby = users ? (
  users.map(userdata => {
    if (userdata.status === "online") {
      var user =
        firebase.firestore().collection("users").doc(userdata.id).get().then(user => {
          return { username: user.data().username };
        })
      return user
    }
    else {
      return null;
    }
  })
) : (null);

How can I access the [Promise] or is there another way to structure this code?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source