I have created a helper function for grabbing a user's name.
export function getUserName (userId) {
if (userId) {
let firstName;
let lastName;
db.collection("users").where("uid", "==", userId)
.get()
.then(function(querySnapshot) {
querySnapshot.forEach(function(doc) {
console.log(doc.id, "=>", doc.data());
firstName = doc.data().firstName;
lastName = doc.data().lastName;
console.log("firstName: " + firstName)
console.log("lastName: " + lastName)
})
});
return (<p>{firstName + " " + lastName}</p>)
}
}
In the console I see the names come through, but not in the return statement. My guess is that the .then hasn't returned and in the meantime, the return has sent the undefined values back to the browser.
Wonder how to avoid this and keep the idea of having a few helper functions I can call for things like displayName, Avatar, etc.
Thanks for any guidance!