javascript - ReduxForm - enableReinitialize 不更新嵌套 FieldArrays 中的值

标签 javascript reactjs redux react-redux redux-form

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

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

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

AddCustomerPOItems = connect(mapStateToProps, poItems)(AddCustomerPOItems)

export default AddCustomerPOItems

此问题在嵌套字段数组中。 当添加新项目时,reducer 将更新状态并初始化字段并正常工作,但如果我修改字段,reducer 可以正常工作并正确更新状态,但值不会被初始化。

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

enter image description here

最佳答案

您可以使用 componentDidMountcomponentDidUpdate 生命周期钩子(Hook)来调用 this.props.initialize(...) 以在数据更新时重新初始化表单变化。

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

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

关于javascript - ReduxForm - enableReinitialize 不更新嵌套 FieldArrays 中的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48983106/

相关文章:

javascript - 添加评级星级 JavaScript 错误

reactjs - 测试自定义 Hook : Invariant Violation: could not find react-redux context value; please ensure the component is wrapped in a <Provider>

javascript - 在react-redux中异步操作后更新状态

javascript - 将类组件转换为函数组件时出错

javascript - 这个 setState({scale : 'c' , temperature}) 可以吗?

reactjs - 如何将 redux-persist 与自定义中间件一起使用

javascript - 如果使用 loadUrl() 而不是 evaluateJavascript() 在 webView 中启动,则 JS 代码有效

Javascript 更新属性

javascript - 客户端人工智能的实际问题

javascript - React Native ListView 到 FlatList 迁移