Redux Form - initialValues not updating when using compose

Alison

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?

JLRishe

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);

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Redux Form - initialValues not updating with state

redux-form fields not rerendering/updating after form loads

Values passed to redux-form initialValues are not rendered

Form input using Redux Form not updating

redux-form textarea value not updating

How to pass Dispatch to action when using redux form

React - redux-form initialValues with draftjs

form & initialValues properties not recognized with multiple forms in one component (redux-form v7.0.4)

TypeScript errors when using Redux-Form with React-Redux connect

Redux Form: initialValues does not set form values

Component not updating when redux store modified

Updating Item Listing using React, Redux. and Redux Form

Redux-form: How to set initialvalues on a wizard form?

React redux-form initialValues isn't loading properly

redux-form infinite loop when setting a date in initialValues

Submitting untouched redux-form with initialValues converts react-select values to array of null

Redux form with compose not working throwing error

initialvalues is not shown in react-select when using with redux form

How to set focus on a TextField\input using a Formik form when initialValues are passed through\bound to props.object?

Redux Form - initialValues not set on page load

Updating initialValues prop on Formik Form does not update input value

Updating database using AJAX form

Dynamically load initialValues in Redux Form

redux-form initialValues not working

Updating state in react-redux when using Immutable

redux: getting rid of boilerplate when updating reducers

page reloads when updating redux state/submitting form

React Redux state not updating when using non mutable methods

updating Formik initialValues with values from separate component