【发布时间】:2020-03-24 14:30:04
【问题描述】:
我有一个 react redux 项目,我想使用 firebase firestore 实时监听器。
现在我有一个获取初始数据的操作:
export const handleInitialData = () => async dispatch => {
const lists = await firestore.collection('lists').get()
if (lists) {
const resolvedLists = lists.docs.map(list => list.data())
return dispatch(receiveLists(resolvedLists))
}
}
你可以看到我使用.collection('lists').get() 并且它有效。
但我想像这样使用.onSnapshot 来使用实时监听器:
export const handleInitialData = () => async dispatch => {
const lists = await firestore.collection('lists').onSnapshot(snapshop => {
let changes = snapshop.docChanges()
})
}
但如果我这样做,我会收到错误:
Unhandled Rejection (TypeError): Cannot read property 'map' of undefined
我不知道从这里去哪里......关于让它工作的任何提示?
我看到有这个库https://github.com/prescottprue/react-redux-firebase
但它使用了我讨厌的recompose,而且作者不再推荐。
会有一些帮助。
【问题讨论】: