useFieldArray
docs
動的にfieldを追加できるようなformで使う
props
name
control
RHFのFormProviderを使っている場合は指定しなくていい
keyName
shouldUnregister
#??
初期値として空のfieldを2つぐらい出したいときはどうすればいい?
普通にuseFormのdefaultValuesに、空を書いておけばいいmrsekut.icon
yupでvalidateする時はどの様に書けばいい?
array()を使うのね
code:ts
const schema = yup.object().shape({
friends: yup.array().of(
yup.object().shape({
firsName: yup.string().required("First Name is required"),
lastName: yup.string().required("Last Name is required")
})
)
});
https://codesandbox.io/s/react-hook-form-array-fields-with-validation-yup-hzdfk?from-embed=&file=/src/index.js
yup.test()を使うと、react-hook-formのonChangeのvalidationが発火しない
examples
https://github.com/react-hook-form/react-hook-form/blob/master/examples/V7/fieldArrayMinLength.tsx