final-form / react-final-form

🏁 High performance subscription-based form state management for React
https://final-form.org/react
MIT License
7.38k stars 480 forks source link

Issues with some possible values of `initialValues` prop #370

Open bwlt opened 5 years ago

bwlt commented 5 years ago

Are you submitting a bug report or a feature request?

Bug report

What is the current behavior?

The <Form /> reinitialise losing his values when rendered inside a component that use the render props pattern. The reinitialisation occurs when the initialValues is computed inside the render prop, and only if any of his keys is an array or an object

What is the expected behavior?

It should not lose his state.

Sandbox Link

https://codesandbox.io/s/1v5lwpr873 In this case the render prop component is the Counter. it is intentionally inserted on top because it could be anything (in my particular case it is a react-apollo Query from which I derive the initialValues). There are some "failing" values for initialValues (NON_WORKING_INITIAL_VALUES_CASE_1, NON_WORKING_INITIAL_VALUES_CASE_2).

What's your environment?

react-final-form@3.6.7 final-form@4.10.0 lastest chrome on osx

Other information

bwlt commented 5 years ago

Found a solution: provide initialValuesEqual prop containing custom logic for comparing two objects. In my opinion the API and the documentation are not clear about this scenario

tlenclos commented 5 years ago

Having this issue also which makes having initial values in FieldArray impossible.

ejmudrak commented 5 years ago

I was struggling to have my form not reinitialize on me, due to attributes of my initialValues being objects.

The solution for me was to use https://github.com/epoberezkin/fast-deep-equal, like so: initialValuesEqual(deepEqual)