Amila Dulanjana
Amila Dulanjana

Reputation: 1914

ReduxForm - enableReinitialize doesn't update values in nested FieldArrays

In my form I am passing the initialvalues through the below code.

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

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

AddCustomerPOItems = connect(mapStateToProps, poItems)(AddCustomerPOItems)

export default AddCustomerPOItems

This issue is in nested field array. When a new item is added reducers will update the state and initialize the fields and works correctly, but if I modify a field, the reducers works fine and updates the state correctly but the values are not getting initialized.

In table 1 its a fieldarray and table 2 (Yellow one) is a nested fieldarray of first table

enter image description here

Upvotes: 3

Views: 1342

Answers (1)

philipp
philipp

Reputation: 16495

You can use the componentDidMount and componentDidUpdate lifecycle hooks to call this.props.initialize(…) to reinitialize the form whenever the data changes.

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

You may also have a look here, since it deals with a quite similar Problem.

Upvotes: 2

Related Questions