firebaseconnect hoc为“collections”返回未定义的值。但是,如果删除“where”参数,它将返回数据。
function mapStateToProps(state) {
return {
contestants: state.firestore.ordered['ContestantsList-contestants'],
votes: state.firestore.ordered['ContestantsList-votes'],
currentUserId: state.firebase.auth.uid,
}
}
export default compose(
firestoreConnect(ownProps => {
// added this console log to verify that ownProps.contestId exists.
console.log('ownProps', {...ownProps})
return ([
{
collection: 'votes',
where: [
['authorId', '==', ownProps.currentUserId],
['contestId', '==', ownProps.contestId],
],
storeAs: 'ContestantsList-votes'
},
{
collection: 'contestants',
orderBy: ['createdAt', 'asc'],
where: ['contestId', '==', ownProps.contestId], // <---- If I remove this line, it works
storeAs: 'ContestantsList-contestants',
},
])
}),
connect(mapStateToProps),
)(ContestantsList);
在上面的代码中,
votes
prop是一个数据数组,正如预期的那样。这个
contestants
道具返回为未定义。我完全不知道为什么会这样。我希望这对一个有经验的firestore用户来说是显而易见的。我是刚到firebase和firestore的。