我正在使用 useFieldArray 从后端 api 获取默认值。我的类别是一个字符串数组。但是,react-hook-form 仅支持对象数组。这是我的猫鼬的架构
type BookDocument = Document & {
title: string
description: string
categories: string[]
language: string
publicationYear: number
}
const bookSchema = new Schema(
{
title: { type: String, required: true },
description: { type: String, required: true },
categories: [{ type: String, requried: true }],
language: { type: String, required: true },
publicationYear: { type: Number, required: true },
},
{ timestamps: true }
)
Run Code Online (Sandbox Code Playgroud)
因此,我必须从前端修改我的表单,如下所示:
type FormData = {
title: string
description: …Run Code Online (Sandbox Code Playgroud)