【问题标题】:how to pass 'auth' or 'profile' object to firestoreConnect() with react-redux-firebase?如何使用 react-redux-firebase 将 'auth' 或 'profile' 对象传递给 firestoreConnect()?
【发布时间】:2019-06-23 20:11:08
【问题描述】:

我不知道如何将“profile”或“auth”道具传递给 firestoreConnect() 函数,以便根据用户 ID 或其他键查询集合或文档(我的代码 sn-p 在下面)。

我可以在我的 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);

【问题讨论】:

    标签: reactjs firebase react-redux-firebase


    【解决方案1】:

    不确定为什么您的代码不起作用(它对我有用)。您是否尝试过 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);
    

    也许这可以让你走上正轨。

    希望你解决它!

    【讨论】:

    • 我认为您需要将连接放在 firestoreConnect 之前。所以firebaseConnect,connect,firestoreConnect.
    【解决方案2】:

    您可能已经解决了这个问题,但如果其他人遇到这个问题,请在此处发布。 你需要在 firestoreConnect 之前移动你的连接方法,所以是这样的:

    export default compose(
      firebaseConnect(),
      connect((state, props) => ({
        projects: state.firestore.ordered.projects,
        profile: state.firebase.profile,
        auth: state.firebase.auth,
      })),
      firestoreConnect(props => [{ collection: 'projects', where: [['uid', '==', props.auth.uid]] }]), <<--THIS LINE DOES NOT WORK
    )(Projects);
    

    【讨论】:

      猜你喜欢
      • 2021-12-26
      • 2020-12-29
      • 2019-05-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多