【发布时间】:2020-08-14 09:45:22
【问题描述】:
我正在尝试查询我的 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.logfavourites 数组时
Array [
House {
"id": undefined,
"imageUri": undefined,
"method": undefined,
"name": undefined,
},
]
火炉
【问题讨论】:
标签: reactjs firebase google-cloud-firestore react-redux