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
- #4069 #4020 fixed initialization and reinitialization — committed to andrew-aladev/redux-form by andrew-aladev 4 years ago
- #4069 #4020 updated initialization and reinitialization according to tests — committed to andrew-aladev/redux-form by andrew-aladev 4 years ago
- #4069 #4020 fixed test with ability to keep onchange values with keepValues — committed to andrew-aladev/redux-form by andrew-aladev 4 years ago
- #4069 #4020 optimized init if needed initial values usage — committed to andrew-aladev/redux-form by andrew-aladev 4 years ago
I believe this is still a bug, my solution is to call
this.props.initialize()
incomponentDidMount()
;^^ Here’s a sandbox: https://codesandbox.io/s/ryo81qz60q
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 updateinitialValues
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 thusinitIfNeeded
is not hitting its first pass at initialization because anextProps
argument is always passed bycomponentDidMount
(the next lifecycle method that callsinitIfNeeded
).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
andcomponentWillMount
, 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 usingcomponentWillMount
, 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!
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
).Same here
I’m having the same problem with
"redux-form": "^8.2.3",
and"react": "^16.8.6",
.Calling
this.props.initialize()
incomponentDidMount();
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:
cWM
,cWRP
, andcWU
. See #4078.react-lifecycles-compat
to continue support for React 15. Until then we cannot avoid the deprecation warnings that come withStrictMode
in React 16.4.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