Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

initialValue overrides state on update #966

Closed
TrySpace opened this issue Dec 21, 2021 · 2 comments
Closed

initialValue overrides state on update #966

TrySpace opened this issue Dec 21, 2021 · 2 comments

Comments

@TrySpace
Copy link
Contributor

TrySpace commented Dec 21, 2021

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.

@devByGelu
Copy link

Could the Form's subscription prop solve the issue?

@andrewAtalent
Copy link

subscription doesn't help anymore.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants