【问题标题】:Redux Form - initialValues not updating when using composeRedux Form - 使用compose时initialValues不更新
【发布时间】:2017-12-02 16:55:08
【问题描述】:

参考:https://redux-form.com/6.7.0/examples/initializefromstate/

我正在尝试实现一个配置文件表单,该表单使用从 api 端点获取的初始数据进行更新。

在引用上面的 redux-form 示例时,我已经能够使示例正常工作。但是,当我将其重构为使用 compose 'initialValues' 时,不会将其插入字段中。

此代码不起作用,initialValues 包含数据但不插入表单字段。

export default compose(
    reduxForm({
        form: 'initializeFromState',
        enableReinitialize : true
    }),
    connect(state => ({
        initialValues: state.profile, // pull initial values from account reducer
    }), actions)
)(EditProfile);

但是,此代码工作正常,只是对参考示例稍作修改。 'initialValues' 也包含数据。

EditProfile = reduxForm({
    form: 'initializeFromState', 
    enableReinitialize: true
})(EditProfile);

EditProfile = connect(
    state => ({
        initialValues: state.profile, 
    }),
    actions, 
)(EditProfile);

export default EditProfile;

它看起来和我很相似,但也许我不能像这样使用 compose?

【问题讨论】:

    标签: reactjs redux redux-form


    【解决方案1】:

    您以错误的顺序将参数传递给compose。组合函数从头到尾执行。因此,您需要颠倒顺序以获得与第二个示例中相同的顺序:

    export default compose(
        connect(state => ({
            initialValues: state.profile, // pull initial values from account reducer
        }), actions),
        reduxForm({
            form: 'initializeFromState',
            enableReinitialize : true
        })
    )(EditProfile);
    

    【讨论】:

      猜你喜欢
      • 2016-12-17
      • 2018-05-08
      • 1970-01-01
      • 1970-01-01
      • 2017-08-26
      • 1970-01-01
      • 2017-11-29
      • 2017-12-18
      • 1970-01-01
      相关资源
      最近更新 更多