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

initialValue overrides state on update

Open TrySpace opened this issue 3 years ago • 2 comments

Bug

What is the current behavior?

Currenlty the initialValue is being used when the component is updated, and resets the form state.

See this question: https://stackoverflow.com/questions/54635276/react-final-form-set-initialvalues-from-props-form-state-resets-on-props-chang

The solution is to memoise the value like: const initVals = useMemo(() => initialValues, [])

What is the expected behavior?

I think the initialValue should only ever be used on the initial render, and not update and reset the form state to the initialValues, as long as they don't change. Although even then I don't think it's appropriate, because it's what I'm used to with input components from libs like @mui

Solution?

I think changing this behaviour might break a lot of use-cases, but perhaps it's a good idea to deprecate the current behaviour of initialValue, and move that effect to the the value prop.

TrySpace avatar Dec 21 '21 13:12 TrySpace

Could the Form's subscription prop solve the issue?

devByGelu avatar Mar 23 '22 06:03 devByGelu

subscription doesn't help anymore.

andrewAtalent avatar Dec 06 '22 18:12 andrewAtalent