What is the current behavior?
React final form does not switch values when field name is dynamically changed during component life, for example if we have:
const { input: { value } } = useField(name)
Imagine name is coming from props and can be dynamically changed.
Initial form state:
{ a: 1, b: 2 }
Renders:
- props
{ name: 'a' }, input: { value: 1 }
- props
{ name: 'b' } input: { value: 1 } - changed the field name, value is still stale
- props
{ name: 'b' } input: { value: 2 } - in next rerender name and value are in sync
So the case can exist where the source changed but the value is still from previous source.
This can break any component that expects specific value for specific source. And can also introduce wrong values (for example during auto save).
What is the expected behavior?
Renders:
- props { name: 'a' }, input: { value: 1 }
- props { name: 'b' } input: { value: 2 } - name and value are in sync in first render after name change
- props { name: 'b' } input: { value: 2 } - ...
Sandbox Link
https://codesandbox.io/s/final-form-field-name-and-value-not-in-sync-when-changing-field-name-okbtn
Click the button to change field name from a to b and watch console for output.
What's your environment?
"react": "16.13.1",
"react-final-form": "6.4.0",
"final-form": "4.19.1"
Any OS/Browser.
What is the current behavior?
React final form does not switch values when field name is dynamically changed during component life, for example if we have:
Imagine
nameis coming from props and can be dynamically changed.Initial form state:
{ a: 1, b: 2 }Renders:
{ name: 'a' }, input:{ value: 1 }{ name: 'b' }input:{ value: 1 }- changed the field name, value is still stale{ name: 'b' }input:{ value: 2 }- in next rerender name and value are in syncSo the case can exist where the source changed but the value is still from previous source.
This can break any component that expects specific value for specific source. And can also introduce wrong values (for example during auto save).
What is the expected behavior?
Renders:
Sandbox Link
https://codesandbox.io/s/final-form-field-name-and-value-not-in-sync-when-changing-field-name-okbtn
Click the button to change field name from
atoband watch console for output.What's your environment?
Any OS/Browser.