Search code examples
javascriptredux-form

Redux Form is not initialised with initial values


I have an application using React Router with an edit attribute page containing <AttributeForm>. The form on this page is properly displaying initialValues passed to it.

On top of the page there's Clone button which basically redirects user to create attribute page. This page also contains <AttributeForm> and I want to prefill form values based on atribute user wants to clone. The problem is that initialValues are not displayed here in the form. I think it has to do something with direct transition from page containing the form to another page containing the same form, but idk. I can see the initialValues correctly via console.log(this.props.initialValues) but they are not displayed.

I also enabled reinitialize, didn't help.

const selector = formValueSelector("AttributeForm")
const mapStateToProps = state => ({
  sourcesArray: getDataSourcesArrayForSelect(state, true),
  dataType: selector(state, "data_type")
})

AttributeForm = connect(mapStateToProps)(AttributeForm)

export default reduxForm({
  form: "AttributeForm",
  touchOnBlur: false,
  enableReinitialize: true
})(AttributeForm)

Solution

  • Solved by setting destroyOnUnmount: false. It was destroying state during page change right after new initialValues was set, hence the form was completely clear.