2 回答
![?](http://img1.sycdn.imooc.com/533e4c7b00013f3c02400205-100-100.jpg)
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();
}, [])
![?](http://img1.sycdn.imooc.com/5458478b0001f01502200220-100-100.jpg)
TA贡献1789条经验 获得超8个赞
尝试await像这样放置异步
useEffect(() => {
...
const getTweets = async () => {
await firebase.firestore().collection('tweet').orderBy('date',
'desc').onSnapshot((singleTweet) => {
....
})
...
}
...
}, [])
添加回答
举报