【发布时间】:2022-08-08 15:02:31
【问题描述】:
我有一个使用useForm 钩子的页面,这个页面是一个多步骤的表单,它们被分离到它们自己的组件中。
像这样的东西:
export default function create(){
const form = useForm({
name: \'\',
content: \'\',
is_published: 0,
some_more_fields_here
});
return (
<div>
<GeneralPageInformation form={form} />
<SeoInformation form={form} />
</div>
)
}
useForm 返回的表单对象如下所示:
InertiaFormProps<{name: string, content: string, is_published: number, rest of your fields}>
现在我尝试做这样的事情
interface IGeneralPageInformation {
form: InertiaFormProps;
}
虽然这确实让我可以访问像 form.processting 和 form.recentlySuccessful 这样的东西
尝试使用 form.setData(\'all available keys should show up here)) 之类的东西时,name 和 content 之类的键不可见
我可以像这样手动声明键
interface IGeneralPageInformation {
form: InertiaFormProps<{name: string, content: string, is_published: number, resf of the fields}>
}
但这显然不是一个非常“可扩展”的解决方案,因为每当表单发生更改时,我都必须手动编辑它。
标签: typescript