学无先后,达者为师

网站首页 编程语言 正文

ant design: Instance created by `useForm` is not connect to any Form element.

作者:_花开富贵 更新时间: 2022-03-15 编程语言

在这里插入图片描述

原因:

ant design在Modal中使用Form,并且通过Form.useForm(), 获取form对象将其挂载到指定的Form表单后,
会出现’Instance created by useForm is not connect to any Form element. Forget to pass form prop’警告,这是由于ant design的Modal组件会在Form表单之前创建,因此当页面初始化form对象会找不到可关联的Form表单,于是出现上述警告

解决:

在Modal组件中添加上 getContainer={false} 即可

<Modal
    getContainer={false}
    {...xxx}
>
    <Form
        form={form}
        {...xxx}
    >
        <Item name="xxx">
            <Input />
        </Item>
    </Form>
</Modal>

原文链接:https://blog.csdn.net/sinat_42338962/article/details/121907846

栏目分类
最近更新