question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Methods of use useFieldArray triggers hooks

See original GitHub issue

Describe 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:closed
  • Created 3 years ago
  • Comments:11 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
michalbundyracommented, Sep 1, 2020

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

0reactions
bluebill1049commented, Sep 1, 2020

agreed.

Read more comments on GitHub >

github_iconTop Results From Across the Web

useFieldArray - Simple React forms validation
Custom hook for working with Field Arrays (dynamic form). The motivation is to provide better user experience and performance. You can watch this...
Read more >
React Hook Form 7 - Dynamic Form Example with useFieldArray
The useEffect() hook updates the 'tickets' field array which triggers a re-render of the component to display the new number of ticket fields....
Read more >
React-Hook-Form Library | Common Use Cases
To use react-hook-form, we need to import and call the useForm hook. ... useWatch, useFormState, useFieldArray ), and many more methods ( e.g....
Read more >
React hook form typescript for trigger method - Stack Overflow
I'm trying to set the type on trigger method. Typescript is complaining that each value is a string when it should be the...
Read more >
React Hook Form - useFieldArray - YouTube
In this session, we are taking a look at the useFieldArray custom hook to manage your dynamic form fields.working example: ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found