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

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

Open jspannu919 opened this issue 2 years ago • 5 comments

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.

jspannu919 avatar May 20 '23 18:05 jspannu919

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

codesandbox-ci[bot] avatar May 20 '23 18:05 codesandbox-ci[bot]

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

bslipek avatar May 25 '23 07:05 bslipek

@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).

jspannu919 avatar May 26 '23 02:05 jspannu919

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

bslipek avatar May 26 '23 08:05 bslipek