Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix form reinitialize problem: using previous initialValues #4020

Merged
merged 1 commit into from Dec 11, 2018
Merged

Fix form reinitialize problem: using previous initialValues #4020

merged 1 commit into from Dec 11, 2018

Conversation

jeniasaigak
Copy link
Contributor

@jeniasaigak jeniasaigak commented May 8, 2018

Problem:

On reinitialize form it calls onChange method with previous initial values.

Workaround:

Use keepDirtyOnReinitialize={true}

Code problem explanation:

When initial values changed and reinitialize enabled:

// enableReinitialize(true) && initialized(true) && (!deepEqual(initialValues, stateInitial)) (true)
const shouldUpdateInitialValues = enableReinitialize && initialized && !deepEqual(initialValues, stateInitial)
// shouldUpdateInitialValues(true)

// initialValues (new initial values), stateInitial (previous initial values)
let initial = initialValues || stateInitial || empty
// initial (new initial values)

// if we should update initial values
if (shouldUpdateInitialValues) {
        // we set old initial values as current values
	initial = stateInitial || empty
}

// here at initial we have previous value instead of current.

Solution

if (**!**shouldUpdateInitialValues) {
It means if we shouldn't update initial values we will set at initial old initial values or empty

@erikras erikras merged commit 8ab0ac5 into redux-form:master Dec 11, 2018
@erikras
Copy link
Member

erikras commented Dec 11, 2018

Published in v8.0.0.

@lock
Copy link

lock bot commented Jan 10, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Jan 10, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants