[英]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.每当我点击 append 按钮时,生成的字段值打印为[object object]
但我想得到一个空白字段。 I want to output like this: "fieldName": ["value1","value2"...n]
.我想要这样的 output: "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.在此代码中,我得到了 output,但每次我都必须删除附加字段中打印的[object obejct]
。
code link: https://codesandbox.io/s/practical-star-jif19c?file=/src/index.js:162-177代码链接: https://codesandbox.io/s/practical-star-jif19c?file=/src/index.js:162-177
Since your array contains only origin names and not objects of origin you should put ""
inside append
function not {}
object.由于您的数组仅包含原始名称而不包含原始对象,因此您应该将""
放入append
function 而不是{}
object。
<Button
variant="contained"
component="label"
type="button"
onClick={() => append('')}
>
Add Items
</Button>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.