【问题标题】:ReduxForm - enableReinitialize doesn't update values in nested FieldArraysReduxForm - enableReinitialize 不会更新嵌套 FieldArrays 中的值
【发布时间】:2018-08-05 14:10:48
【问题描述】:

在我的表单中,我通过以下代码传递初始值。

function mapStateToProps(state) {
     return {
       initialValues: {
       POItems: state.poItems.poItems
     }
  }
}

AddCustomerPOItems = reduxForm({
  form: 'AddCustomerPOItemsForm',
  enableReinitialize: true,
})(AddCustomerPOItems)

AddCustomerPOItems = connect(mapStateToProps, poItems)(AddCustomerPOItems)

export default AddCustomerPOItems

此问题出在嵌套字段数组中。 添加新项目时,reducers 将更新状态并初始化字段并正常工作,但如果我修改字段,reducers 工作正常并正确更新状态,但值未初始化。

在表 1 中,它是一个字段数组,表 2(黄色)是第一个表的嵌套字段数组

【问题讨论】:

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


    【解决方案1】:

    您可以使用componentDidMountcomponentDidUpdate 生命周期挂钩调用this.props.initialize(…),以便在数据更改时重新初始化表单。

    https://redux-form.com/7.2.3/docs/api/props.md/#-code-initialize-data-object-function-code-

    你也可以看看here,因为它处理一个非常相似的问题。

    【讨论】:

      猜你喜欢
      • 2019-07-28
      • 2021-09-24
      • 2018-04-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-08
      • 2021-11-04
      • 2019-03-13
      相关资源
      最近更新 更多