如何解决反应查询Firestore数据
我正在尝试查询Redux存储中的数据以从Firebase中获取数据,但是却无法定义 我要去哪里错了?请有人可以帮助我。我查询数据的方式是否错误?
房屋分类:
class House {
constructor(
id,name,imageUri,method
){
this.id = id;
this.name = name;
this.imageUri = imageUri
this.method = method;
}
}
export default House
Redux商店:
import firebase from 'firebase'
import House from '../../models/House'
const initialState = {
favourites :[],}
const FavsReducer = (state=initialState,action) =>{
switch(action.type){
case TOGGLE_FAVOURITE:
let myfav = new House()
firebase.firestore()
.collection('Posts')
.where('postId','==',action.houseId)
.get()
.then(snapshots => {
snapshots.docs.forEach(doc=>{
myfav = new House(
doc.data().id,doc.data().name,doc.data().image,doc.data().method
)
})
})
return {...state,favourites: state.favourites.concat(house)}
default:
return state
}
}
export default FavsReducer
当我console.log
favourites
数组时
Array [
House {
"id": undefined,"imageUri": undefined,"method": undefined,"name": undefined,},]
消防站
解决方法
怎么样:
firebase.firestore()
.collection('Posts')
.doc(action.houseId)
.get()
.then((docRef) => { console.log(docRef.data()) })
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。