2

reference: https://redux-form.com/6.7.0/examples/initializefromstate/

I am trying to implement a profile form that updates with initial data that is fetched from an api endpoint.

I've been able to get the example to work when referencing the redux-form example above. However when I refactor it to use compose 'initialValues' does not get inserted into the fields.

This code does not work, initialValues contains data but does not insert into form fields.

export default compose(
    reduxForm({
        form: 'initializeFromState',
        enableReinitialize : true
    }),
    connect(state => ({
        initialValues: state.profile, // pull initial values from account reducer
    }), actions)
)(EditProfile);

However this code works which is just slightly modified from reference example. 'initialValues' also contains data.

EditProfile = reduxForm({
    form: 'initializeFromState', 
    enableReinitialize: true
})(EditProfile);

EditProfile = connect(
    state => ({
        initialValues: state.profile, 
    }),
    actions, 
)(EditProfile);

export default EditProfile;

It's looks similar to me but maybe I can't use compose like this?

1 Answer 1

6

You're passing the arguments to compose in the wrong order. Composed functions execute from the end toward the beginning. So you'll need to reverse the order to have the equivalent of what you've got in the second example:

export default compose(
    connect(state => ({
        initialValues: state.profile, // pull initial values from account reducer
    }), actions),
    reduxForm({
        form: 'initializeFromState',
        enableReinitialize : true
    })
)(EditProfile);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.