final-form / react-final-form

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

fix(useField): Fix no re-render on initialValue change #1034

Open jspannu919 opened 1 year ago

jspannu919 commented 1 year ago

Currently useField doesn't retriggers properly if the initialValue is changed (Added test scenario). Added explicit check for initial value change to prevent deepEqual overheads.

codesandbox-ci[bot] commented 1 year ago

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit fe2fb36682b5981b441038a86301b3883c5ce8c7:

Sandbox Source
final-form/react-final-form Configuration
final-form/react-final-form Configuration
final-form/react-final-form Configuration
final-form/react-final-form Configuration
final-form/react-final-form Configuration
bslipek commented 1 year ago

IMO this is fine, you should not listen for initialValues after form initialization. Why you need this?

jspannu919 commented 1 year ago

@bslipek In data driven forms (Ref: https://github.com/data-driven-forms/react-forms ) for conditionally hiding the fields, the fields are wrapped with a Field component so that they get re-rendered when the value in any of the parent attribute change(Ref: https://github.com/data-driven-forms/react-forms/blob/84c4cb8861d689cb87ba68100fe7d3acfd667655/packages/react-form-renderer/src/form-renderer/render-form.js#L47). So, due to the above issue the conditional visibility doesn't works if we reverse the order of the fields(Ref: https://stackblitz.com/edit/1dkk8s-rd1ejn?file=schema.js).

bslipek commented 1 year ago

I got your point. But still think that this is final-form problem. But I am just a observer here :)