2 回答

TA贡献1866条经验 获得超5个赞
取决于您可能想要切换到的功能.get
但由于这应该像 @Nooruddin 建议的那样是异步的,因此您需要有一个.then才能使用集合的快照
尝试:
useEffect(() => {
const getTweets = async() => {
let newArray = []
await firebase.firestore().collection('tweet').orderBy('date', 'desc').get()
.then(((snapshot) => {
snapshot.forEach((singleTweet) => {
newArray.push(singleTweet.data())
})
}))
showLoader()
setTweets(newArray)
if (newArray) {
hideLoader()
}
}
getTweets();
}, [])

TA贡献1789条经验 获得超8个赞
尝试await像这样放置异步
useEffect(() => {
...
const getTweets = async () => {
await firebase.firestore().collection('tweet').orderBy('date',
'desc').onSnapshot((singleTweet) => {
....
})
...
}
...
}, [])
添加回答
举报