I have an asynchronous function in a react-native project that does work on firebase's firestore. my issue is NOT with returning data from an async function. After getting some data, I have mapped it, and need to return from inside map
async updateConvo() {
const snapshot = await firebase
.firestore()
.collection("conversations")
.where(
"members",
"array-contains",
this.state.recipient && this.props.user.email
)
.get();
const arr = snapshot.docs.map(doc => {
alert("inner alert: " + doc.id);
return doc.id;
});
alert("outer alert: "+ arr[0]);
return arr[0];
}
Inner alert always executes and I get see the alert eg "inner alert: document-ID "
The outer alert never fires, and when I just return arr[0]
its undefined when I implement the updateConvo
function elsewhere.
How to I successfully return doc.id
from the map function and finally the whole function?