我目前正在构建一个组件,允许用户编辑他们的个人资料设置。表单包含以下字段:
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)
但上面的内容不起作用...如何添加其他状态对象中的其他initialValues?
我也尝试过以下操作,但这不是设置值:
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)
答案 0 :(得分:0)
请尝试以下代码,但您必须确保自己拥有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)