Skip to content

Commit

Permalink
redux-form#4069 redux-form#4020 optimized init if needed initial valu…
Browse files Browse the repository at this point in the history
…es usage
  • Loading branch information
andrew-aladev committed Jan 17, 2020
1 parent a980cac commit 38a95a7
Showing 1 changed file with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions src/createReduxForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -341,22 +341,25 @@ const createReduxForm = (structure: Structure<*, *>) => {
updateUnregisteredFields
} = this.props

if (nextProps && nextProps.initialValues) {
const shouldReinitialize =
nextProps.initialized &&
enableReinitialize &&
!deepEqual(initialValues, nextProps.initialValues)
const shouldUpdateInitial =
!nextProps.initialized || shouldReinitialize

if (shouldUpdateInitial) {
const keepDirty = nextProps.initialized && keepDirtyOnReinitialize

initialize(nextProps.initialValues, keepDirty, {
keepValues: nextProps.keepValues,
lastInitialValues: initialValues,
updateUnregisteredFields: nextProps.updateUnregisteredFields
})
if (nextProps) {
if (nextProps.initialValues) {
const shouldReinitialize =
nextProps.initialized &&
enableReinitialize &&
!deepEqual(initialValues, nextProps.initialValues)
const shouldUpdateInitial =
!nextProps.initialized || shouldReinitialize

if (shouldUpdateInitial) {
const keepDirty =
nextProps.initialized && keepDirtyOnReinitialize

initialize(nextProps.initialValues, keepDirty, {
keepValues: nextProps.keepValues,
lastInitialValues: initialValues,
updateUnregisteredFields: nextProps.updateUnregisteredFields
})
}
}
} else if (initialValues) {
const shouldUpdateInitial = !initialized || enableReinitialize
Expand Down

0 comments on commit 38a95a7

Please sign in to comment.