use*_*385 5 firebase reactjs react-redux-firebase
我不知道如何将 'profile' 或 'auth' props 传递给 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);
Run Code Online (Sandbox Code Playgroud)
小智 3
不确定为什么你的代码不起作用(它对我有用)。您是否在 firestoreConnect 中尝试过控制台日志记录道具?像这样:
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);
Run Code Online (Sandbox Code Playgroud)
也许这能让你走上正轨。
希望你能解决!
| 归档时间: |
|
| 查看次数: |
1093 次 |
| 最近记录: |