funciton
checkIfSeen = (uid, news_id) => {
var seen = false;
const docRef = DB.informationsCollection.doc(news_id).collection('users').doc(uid);
docRef.get()
.then((docSnapshot) => {
if (docSnapshot.exists) {
seen = true;
console.log(seen);
// returns true
}
});
console.log(seen);
// returns false
}
Problem
It returns true after if (docSnapshot.exists) {
but returns false in the last of the function.
Does anybody know why this happens?
I would appreciate it if you could give me any adivce.
updated
checkIfSeen = (uid, news_id) => {
const docRef = Fire.shared.informationsCollection.doc(news_id).collection('users').doc(uid);
docRef.get()
.then((docSnapshot) => {
if (docSnapshot.exists) {
this.alreadySeen();
} else {
this.notSeen();
}
});
}
alreadySeen = () => {
return true;
}
notSeen = () => {
return false;
}