Methods of use useFieldArray triggers hooks
See original GitHub issueDescribe the bug
Issue since version 6.5.3, version 6.5.2 works as expected (for append
).
I need to call append
in useEffect
hook, but unfortunately it’s not working as I would expect.
To use append
in hook I need to pass it as dependency and it causes problem. If I am not adding it to dependency list all works as expect, but then I am getting warning in console, that it should be a dependency.
I can have a workaround for that easily with additional state value, but I consider it as a bug, as setValue
from the form works as expected - see below.
To Reproduce See codesandbox below
Codesandbox link (Required) https://codesandbox.io/s/react-hook-form-usefieldarray-forked-wrmyj?file=/src/index.js:424-438
Click one of “append”, ~“prepend”~ or “delete” and check console output.
Expected behavior All hooks are triggered only once - on loading, but should not be called when field is appended/prepended/removed.
I’ve checked also how it works with setValue
from the form:
https://codesandbox.io/s/react-hook-form-v6-setvalue-forked-inyki?file=/src/index.jsx
and here all is fine - when we click “Set First Name Value”, which triggers setValue
the hook is not called, as I would expect.
Desktop (please complete the following information):
- OS: macOS
- Browser Safari/Chrome
- Version latest stable
Issue Analytics
- State:
- Created 3 years ago
- Comments:11 (11 by maintainers)
Top GitHub Comments
@bluebill1049 For the time being I am fine with 2 if it is not causing any other issues (performance, etc…).
It would be nice to avoid ref, but we can do it later as another improvement.
agreed.