This method is supposed to return a list of users but returning an empty array. When I console log inside the forEach loop, it prints the data but not outside of it.
get getAllUsers() {
const usersList = [];
firebase
.firestore()
.collection('users')
.get()
.then(snapshot => {
snapshot.forEach(user => {
usersList.push(user.data());
console.log(user.data());
});
});
return usersList; // Array [] or undefined when indexed
}
On Home.js, I call it here.
componentDidMount() {
const list = fireStoreDB.getAllUsers;
console.log(list);
}
Array [] is the console log of the method and the objects are the console log from the forEach loop.
