react-final-form icon indicating copy to clipboard operation
react-final-form copied to clipboard

Form values reset on render with deep initialValues

Open antoniomadonna opened this issue 5 years ago • 4 comments

Are you submitting a bug report or a feature request?

bug report

What is the current behavior?

When the form has deep (with nested properties) initialValues and re-renders it will reset all the form state.

What is the expected behavior?

It should not reset entered values

Sandbox Link

https://codesandbox.io/s/react-final-form-nested-values-bug-sn0mc

What's your environment?

"react-final-form": "^6.3.5", "final-form": "^4.18.7",

Other information

antoniomadonna avatar Feb 05 '20 11:02 antoniomadonna

You can make your deep equal, for example with lodash.isequal in initialValuesEqual. But yes it's a bug

simstefani avatar Feb 06 '20 17:02 simstefani

I too have had this happen when using an object as the value with nested values.

harrycollin avatar Feb 08 '20 00:02 harrycollin

Any updates here?

veeralpatel avatar Mar 23 '21 03:03 veeralpatel

Thanks @simstefani for making us aware of initialValuesEqual.

An alternative solution to the deep equal (depending on the use case) would be to set initialValuesEqual={() => true}. The form can then be reset with a key prop or via formApi.restart(initialValues?: InitialFormValues) if needed.

pstrh avatar Jan 24 '23 16:01 pstrh