Version Number
7.80
Codesandbox/Expo snack
https://codesandbox.io/p/devbox/rhf-subscribe-clearerrors-forked-slgmgy
Steps to reproduce
- Click "reset". See that the
Watch component is re-rendered twice.
- Comment out the
useFieldArray line. Refresh the CSB and click "reset" again. Now, the component only re-renders once.
Expected behaviour
Clicking the reset button should only cause a single re-render. The presence or absence of useFieldArray should not change the rendering behavior.
The issue here seems to be that reset() notifies all subscribers once, and then useFieldArray notifies subscribers a second time (because the fields change triggers the useEffect.
|
_subjects.array.next({ |
|
values: { ...values }, |
|
}); |
|
control._subjects.state.next({ |
|
name, |
|
values: cloneObject(control._formValues) as TFieldValues, |
|
}); |
What browsers are you seeing the problem on?
Chrome
Relevant log output
Rendered: 1
Rendered: 2
Calling reset()
Rendered: 3
Rendered: 4
Code of Conduct
Version Number
7.80
Codesandbox/Expo snack
https://codesandbox.io/p/devbox/rhf-subscribe-clearerrors-forked-slgmgy
Steps to reproduce
Watchcomponent is re-rendered twice.useFieldArrayline. Refresh the CSB and click "reset" again. Now, the component only re-renders once.Expected behaviour
Clicking the reset button should only cause a single re-render. The presence or absence of
useFieldArrayshould not change the rendering behavior.The issue here seems to be that
reset()notifies all subscribers once, and thenuseFieldArraynotifies subscribers a second time (because thefieldschange triggers theuseEffect.react-hook-form/src/logic/createFormControl.ts
Lines 1753 to 1755 in 5b2b743
react-hook-form/src/useFieldArray.ts
Lines 461 to 464 in 5b2b743
What browsers are you seeing the problem on?
Chrome
Relevant log output
Rendered: 1 Rendered: 2 Calling reset() Rendered: 3 Rendered: 4Code of Conduct