'How can I get an empty field when I click on the append using the useFieldArray of React-hook-form?

Whenever I click on the append button, the generated field value printed as a [object object] but I want to get a blank field. I want to output like this : "fieldName" : ["value1","value2"...n]. In this code, I get the output as I like, but every time I have to remove the [object obejct] that is printed in the appended field. Example Image:

code link : https://codesandbox.io/s/practical-star-jif19c?file=/src/index.js:162-177



Solution 1:[1]

Since your array contains only origin names and not objects of origin you should put "" inside append function not {} object.

<Button
    variant="contained"
    component="label"
    type="button"
    onClick={() => append('')}
>
    Add Items
</Button>

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Gnanavel