Skip to content

useFieldArray not working when append/insert called multiple times quickly #5323

@harshzalavadiya

Description

@harshzalavadiya

Describe the bug
When using fieldArray in react-hook-form@7 if append is called multiple times it does not work as expected, I don't know weather this was designed intentionally since it works when timeout is added before calling

use case: In our application I have to create multiple dropdowns based on parsed excel sheet to map fields, so I can't provide value as defaultValues, I have to create N fields at runtime all at once

To Reproduce
see useState method of codesandbox

Codesandbox link (Required)
https://codesandbox.io/s/react-hook-form-usefieldarray-forked-05z9z?file=/src/index.js

Expected behavior
It should create multiple fields

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: [e.g. iOS] Linux
  • Browser [e.g. chrome, safari] chrome and firefox
  • Version [e.g. 22] chrome@90 and firefox@88

Smartphone (please complete the following information):

  • Device: [e.g. iPhone6]
  • OS: [e.g. iOS8.1]
  • Browser [e.g. stock browser, safari]
  • Version [e.g. 22]

Additional context
If you try it with insert() from useFieldArray internally it creates fields but fields object from useFieldArray only shows 1 item as above

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions