我不知道如何将“profile”或“auth”属性传递给 firestoreConnect() 函数,以便根据用户 ID 或其他键查询集合或文档(我的代码片段如下)。
我可以在 jsx 代码中访问“auth”和“profile”对象,但我找不到在 firestoreConnect() 函数中使用它们的方法(我收到错误: TypeError: Cannot read property 'uid' of undefined
)。如果我对一些 uid 进行硬编码,那么一切正常,但我无法将其作为 props 值传递。
任何建议都将受到高度赞赏!
export default compose(
firebaseConnect(),
firestoreConnect(props => [{ collection: 'projects', where: [['uid', '==', props.auth.uid]] }]), <<--THIS LINE DOES NOT WORK
connect((state, props) => ({
projects: state.firestore.ordered.projects,
profile: state.firebase.profile,
auth: state.firebase.auth,
}))
)(Projects);
最佳答案
不确定为什么你的代码不起作用(它对我有用)。您是否在 firestoreConnect 中尝试过控制台日志记录 Prop ?像这样:
export default compose(
firebaseConnect(),
firestoreConnect(props => {
console.log(props)
return [
{ collection: 'projects', where: [['uid', '==', props.auth.uid]] }
]
}),
connect((state, props) => ({
projects: state.firestore.ordered.projects,
profile: state.firebase.profile,
auth: state.firebase.auth,
}))
)(Projects);
也许这能让你走上正轨。
希望你能解决!
关于reactjs - 如何使用react-redux-firebase将 'auth'或 'profile'对象传递给firestoreConnect()?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54442404/