需求背景:
后台管理系统的一个弹窗同时承接新增和编辑功能(编辑时表单数据回填)

不要给Form 加 initialValues
因为 和 Form 一起配合使用时,设置 destroyOnClose 也不会在 Modal 关闭时销毁表单字段数据
解决如下:

 React.useEffect(() => {
    if (!updateItem) {
      form.resetFields();
    } else {
      form.setFieldsValue(updateItem);
    }
  }, [modalVisible]);

使用resetFields和setFieldsValue即可

Logo

快速构建 Web 应用程序

更多推荐