question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Field name and value not in sync when changing field name

See original GitHub issue

What 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:

  1. props { name: 'a' }, input: { value: 1 }
  2. props { name: 'b' } input: { value: 1 } - changed the field name, value is still stale
  3. 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:

  1. props { name: ‘a’ }, input: { value: 1 }
  2. props { name: ‘b’ } input: { value: 2 } - name and value are in sync in first render after name change
  3. 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:open
  • Created 3 years ago
  • Reactions:3
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
ruscodercommented, Jan 14, 2021

I also encountered this issue. Workaround for now - specify key={fieldName} attribute in the parent component.

0reactions
gbiryukovcommented, Feb 28, 2022

also facing this issue on most recent versions.

it happens because useField returns same name as it receives from props while related value comes from state that is updated in effect after name 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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found