1
votes

I tried to load with initial values for the form in two ways. First inside the FormComponent like

FormComponent= reduxForm({
    form: 'initializeFromState' 
})(FormComponent)

FormComponent= connect(
    state => ({
        initialValues: { name: 'ABC' }
    }),
)(FormComponent)

export default FormComponent

This is the copy of the document in the Redux form library, but the value is not populating in the form. The form name and variable name i used for the rest of the codes are correct.

The second method is by passing the initialValues from the ParentComponent like

<FormComponent initialValues={{ name: 'ABC' }} />

which gives the form populated correctly with name ABC.

What is the issue in the first method?

I tried with consoling the this.props in both methods inside the FormComponent.

First method gives initialValues: { name: 'ABC' } which the value is not populated in the form.

Second method gives initialValues: Map size: 1 __altered: false __hash: undefined __ownerID: undefined which is in the format something for the redux form and works correctly for the form.

I just want to use in the first method. What changes should i make to work it correctly?

try changing your unique identifier for your form from 'initializeFromState' to 'FormComponent' ? - Atin Singh
Is that required to have the same name for the component and the form? - Hareesh
I am not too sure but i think so. But it totally depends on where you are using it. - Atin Singh