redux-form: initialValues no longer "syncs" data with state

I just updated to v4.1.5. Previously when I set initialValues for a component, if the bit of state that informed initialValues ever changed, it would “sync” or overwrite the data for the redux form properties. Now, while it does initially load data from your state, it never updates anything again unless you force it to with a resetForm() call.

I have read all of #370 as well as the past few release notes and it appears that this change in behavior was intentional. I totally agree with everyone that calling that property initialValues when it did more than just initialize values was really confusing. However, I don’t think that means we should completely drop the option to use that type of functionality. Could we keep initialValues working the same way that it does now (just initializes values, nothing more) but add something new that both initializes values and updates those values when the source piece of state changes. In essence it would link or sync your redux form component to a piece of state, just like how initialValues used to work.

At the moment, the only workaround I can see is to use initialValues and then find every place that its corresponding piece of state could change and add a resetForm() call. I can totally foresee an instance where this solution wouldn’t work so well, if you had a component that modified that piece of state that was not connected to redux form at all, but you wanted the change reflected in your redux form component.

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 32 (5 by maintainers)

Most upvoted comments

@XoJIoD89 an elegant way has been added in v6 (multiple ways in fact!). Check out the Initializing from State example. The easiest way to get the behavior I describe in my post is to set initialValues in the connected state to whatever you want it to be and then set enableReinitialize: true in the reduxForm constructor. It is literally as simple as that. I don’t believe a solution was ever implemented for v5 of the library but if you’re able to do so, it really is worth the upgrade (v6 rocks).