Reputation: 117
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?
Upvotes: 2
Views: 395
Reputation: 101680
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);
Upvotes: 6