redux-form: [v7.4.0] initialValues not working

Are you submitting a bug report or a feature request?

bug report

What is the current behavior?

initialValues prop is not working on initial mount after update to 7.4.0

Sandbox Link

I’ve modified the Initialize from state demo just to show the issue. I’ve just change:

 state => ({
    initialValues: data
 }),

to get values directly from the variable instead after clicking the button.

https://codesandbox.io/s/ox3p66023q

As you can see the fields are empty. If you change the redux-form version to 7.3.0 it works.

What’s your environment?

redux-form 7.4.0

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 23
  • Comments: 38 (7 by maintainers)

Commits related to this issue

Most upvoted comments

I believe this is still a bug, my solution is to call this.props.initialize() in componentDidMount();

Bug still can be reproduced under "redux-form": "8.2.2" and "react": "^16.8.6". The issue has to be reopened.

Published ACTUAL fix in v7.4.2.

I’m just glad to see the Redux Forms authors have as tough a time testing their library as I do.

Actually, I finally found an issue someone already filed for what I’m talking about: #3459 (initialize() action creator should update initialValues props)

I just spent a couple hours trying to diagnose this as well. Pinning to version 7.3.0 in your package.json will fix the issue.

It appears that, in createReduxForm, componentWillMount is no longer being called, and thus initIfNeeded is not hitting its first pass at initialization because a nextProps argument is always passed by componentDidMount (the next lifecycle method that calls initIfNeeded).

This is because the method name changed to UNSAFE_componentWillMount in order to support React 16’s unsafe versions of deprecated lifecycle methods. By doing so, support for React v15 is now broken in v7.4.0.

I would imagine that having two methods, UNSAFE_componentWillMount and componentWillMount, living side by side doing the same work, would guarantee full support for React 15 and 16, but I haven’t tried yet. EDIT: Or you could just go back to only using componentWillMount, as that is still going to be supported until React 17 comes out, at which point this package could do a major version breaking change bump to support React 17.

Maintainers, please let me know if you’d like a PR with my proposed solution!

I believe this is still a bug, my solution is to call this.props.initialize() in componentDidMount();

One more option: componentDidMount { this.props.initialize(this.props.myFormData) }

I can confirm this issue on react 15.6.2. The redux-form/INITIALIZE event does not fire

This issue can be easily reproduced by providing same initialValues twice.

I can confirm this is still an issue (redux-form@8.2.6 & react@16.10.2).

I’m having the same problem with "redux-form": "^8.2.3", and "react": "^16.8.6",.

Calling this.props.initialize() in componentDidMount(); worked for me!

Same here

I’m having the same problem with "redux-form": "^8.2.3", and "react": "^16.8.6",.

Calling this.props.initialize() in componentDidMount(); worked for me!

@jedwards1211 could you elaborate? I seem to have the same issue with version 7.4.2 and React 16.5.0, but there is a very real possibility I might have overlooked something…

@gustavohenke, @jpdesigndev, @JoshMock Let’s be clear:

  • The hotfix should be to revert to the straight cWM, cWRP, and cWU. See #4078.
  • The actual fix is to migrate all uses of these old life cycle methods, when doing so we use react-lifecycles-compat to continue support for React 15. Until then we cannot avoid the deprecation warnings that come with StrictMode in React 16.4.
  • Use of UNSAFE_ methods are only appropriate when the React version is known to be 16+ (i.e. for application authors).

See: open-source-project-maintainers & gradual-migration-path sections of the react blogs update-on-async-rendering