Reputation: 1914
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
Upvotes: 3
Views: 1342
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