Field name and value not in sync when changing field name
See original GitHub issueWhat is the current behavior?
React final form does not swtiche 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.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:3
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Field does not sync in Pardot - Salesforce Help
There are many different causes why your field might not be syncing in Pardot or Salesforce. Here's a list of possibilities you can...
Read more >Field Name not change? - Microsoft Community Hub
I have a Column, type: Lookup. The original name is "Country LK". Then I use Power App customize my form, but I don't...
Read more >Marketo is unable to sync to the new field name an...
Resolution: Once a new field name and type is picked up by Marketo during the first sync, Marketo keeps the original properties. A...
Read more >Editing field names and descriptions - Amazon QuickSight
You can change any field name and description from what is provided by the data source. If you change the name of a...
Read more >How can I update a connected field whose column name ...
We recently had to make a change to the CSV file that is used in a connected table via Quickbase Sync. This column...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I also encountered this issue. Workaround for now - specify
key={fieldName}
attribute in the parent component.also facing this issue on most recent versions.
it happens because
useField
returns samename
as it receives from props while relatedvalue
comes from state that is updated in effect aftername
change.possible solution is to have second version of
name
also in state and update it synchronously with value. this way hook can return values in sync