【问题标题】:With redux form, how to combine values for initialValues?使用redux形式,如何组合initialValues的值?
【发布时间】:2017-08-12 20:52:38
【问题描述】:

我目前正在构建一个组件以允许用户编辑他们的个人资料设置。该表单具有以下字段:

first_name
last_name

redux 表单当前正在正确设置 initialValues,如下所示:

Profile = connect(
  state => ({
    initialValues: state.profiles.find(el => el.id === state.currentUser.user_id)
  })
)(Profile)

问题是我还需要在这个表单中包含 UserSettings,所以我正在尝试这样做:

    Profile = connect(
      state => ({
        initialValues: state.profiles.find(el => el.id === state.currentUser.user_id),
        initialValues: {
          notification_email_product_feature_updates: state.user_settings.notification_email_product_feature_updates
}
      })
    )(Profile)

但上述方法不起作用...如何添加其他处于不同状态对象的初始值?

我也尝试了以下方法,但这不是设置值:

Profile = connect(
  state => ({
    initialValues: {
      first_name: state.profiles.find(el => el.id === state.currentUser.user_id) ? state.profiles.find(el => el.id === state.currentUser.user_id).first_name : '',
    }
  })
)(Profile)

【问题讨论】:

    标签: reactjs redux redux-form react-redux-form


    【解决方案1】:

    试试下面的代码,但你必须确保你在这个state.user_settings.notification_email_product_feature_updates中得到了一些东西:

        Profile = connect(
        state => ({
            initialValues: 
            {
                currentUser: state.profiles.find(el => el.id === state.currentUser.user_id),
                settings: state.user_settings.notification_email_product_feature_updates
            }
        })
        )(Profile)
    

    【讨论】:

      猜你喜欢
      • 2016-11-10
      • 2016-09-04
      • 2020-09-28
      • 1970-01-01
      • 1970-01-01
      • 2018-05-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多