final-form / final-form/react-final-form
keepDirtyOnReinitialize gets active from the next render
- Dominant language
- JavaScript
- Stars
- 7.4k
- Forks
- 497
- PR merge metrics
- No merged PRs in 30d
Description
Having a:
```
```
`keepDirtyOnReinitialize` behavior gets active, not for the current render, but from the next render.
I have traced the issue down to `ReactFinalForm.js`:
```
useWhenValueChanges(
initialValues,
() => {
form.setConfig('initialValues', initialValues)
},
initialValuesEqual || shallowEqual
)
useWhenValueChanges(keepDirtyOnReinitialize, () => {
form.setConfig('keepDirtyOnReinitialize', keepDirtyOnReinitialize)
})
```
These hooks get executed in order, so `initialValues` initialize the form, even before `keepDirtyOnReinitialize` trigger its value.
Simple exchange the two fragments place, fixes the problem.
```
useWhenValueChanges(keepDirtyOnReinitialize, () => {
form.setConfig('keepDirtyOnReinitialize', keepDirtyOnReinitialize)
})
useWhenValueChanges(
initialValues,
() => {
form.setConfig('initialValues', initialValues)
},
initialValuesEqual || shallowEqual
)
```
Contributor guide
Assessment
This issue has not been assessed yet.