【发布时间】:2021-08-10 12:07:47
【问题描述】:
我希望我的函数在 ((querySnapshot) => {... 函数完成后返回。
目前,我的noOpponent函数在调用后总是返回false,这可能是因为它在((querySnapshot) => {...函数完成之前返回,所以它在state设置true之前返回。我已经尝试使用var a = await noOpponent(key) 调用 noOpponent 函数,但它不起作用,因为正如我已经写的那样,我想我必须等待 ((querySnapshot) => {... 函数。我该怎么做?
export const noOpponent = (Key) => {
var state = false;
console.log("key: " + Key)
duettsRef
.where("key", "==", Key)
.where("player1", "!=", firebase.auth().currentUser.uid)
.where("player2", "==", "")
.limit(1)
.get()
.then((querySnapshot) => {
console.log("QuerysnapshotResult: " + !querySnapshot.empty);
state = true;
})
return state;
};
【问题讨论】:
标签: reactjs firebase react-native google-cloud-firestore google-cloud-functions