在用 antd4 写报表,遇到一个 Form 组价的 Waring。
Warning: Instance created by useForm is not connect to any Form element. Forget to pass form prop?
当前的场景在一个 Modal 中添加 Form 表单采集数据,代码大致如下:
<Modal
title="表格列设置"
...
>
<Form
form={form}
...
>
...
</Form>
</Modal>;
解决方法在官方文档中有对应内容:
这是因为你在调用 form 方法时,Modal 还未初始化导致 form 没有关联任何 Form 组件。你可以通过给 Modal 设置
forceRender
将其预渲染。
给 Modal 组件加上 forceRender 属性即可。
<Modal
forceRender
title="表格列设置"
...
>
<Form
form={form}
>
...
</Form>
</Modal>;