reactjs - 如何使用react-redux-firebase将 'auth'或 'profile'对象传递给firestoreConnect()?

标签 reactjs firebase react-redux-firebase

我不知道如何将“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/

相关文章:

reactjs - Typesafe React 装饰器无法识别传递函数的 ReturnType

firebase - 通过rest api发送消息时如何设置通知 channel ?

reactjs - React Redux Firebase 中的私有(private)路由不起作用

react-native-firebase vs react-redux-firebase?

reactjs - Firestore 按数组的字段值查询

javascript - React 组件作为背景图片

javascript - 使用 formData 和 Axios 的 PATCH 请求的输入数据在 Laravel 上不可用

javascript - 如何从对象 [Firebase 唯一键] 中检索数据

git - 如何修复 .git 暴露的 firebase 漏洞

javascript - 如何在 React 中使用 fetch 和表单数据来发布对象?