From d40988b64e6d315fc95f2f217d0f8643e6cfd216 Mon Sep 17 00:00:00 2001 From: HQ-Lin Date: Mon, 5 Dec 2022 15:48:48 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20form=20ts=20?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B=E8=AD=A6=E5=91=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/form/FormContext.tsx | 2 +- src/form/hooks/useForm.ts | 2 +- src/form/type.ts | 20 ++++++++++---------- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/form/FormContext.tsx b/src/form/FormContext.tsx index 4b4f2dee8..e7e03ad1a 100644 --- a/src/form/FormContext.tsx +++ b/src/form/FormContext.tsx @@ -21,7 +21,7 @@ const FormContext = React.createContext<{ formMapRef: React.RefObject>>; onFormItemValueChange: (changedValue: Record) => void; }>({ - form: {}, + form: undefined, labelWidth: '100px', labelAlign: 'right', layout: 'vertical', diff --git a/src/form/hooks/useForm.ts b/src/form/hooks/useForm.ts index f93aa59c0..97254f83f 100644 --- a/src/form/hooks/useForm.ts +++ b/src/form/hooks/useForm.ts @@ -75,7 +75,7 @@ class FormStore { } export default function useForm(form?: InternalFormInstance) { - const formRef = useRef({}); + const formRef = useRef(Object.create({})); const [, forceUpdate] = useState({}); // eslint-disable-next-line diff --git a/src/form/type.ts b/src/form/type.ts index 57034acd8..38a17ed0c 100644 --- a/src/form/type.ts +++ b/src/form/type.ts @@ -104,7 +104,7 @@ export interface FormInstanceFunctions { /** * 清空校验结果。可使用 fields 指定清除部分字段的校验结果,fields 值为空则表示清除所有字段校验结果。清除邮箱校验结果示例:`clearValidate(['email'])` */ - clearValidate?: (fields?: Array) => void; + clearValidate: (fields?: Array) => void; /** * 获取 form dom 元素 */ @@ -116,39 +116,39 @@ export interface FormInstanceFunctions { /** * 获取单个字段值 */ - getFieldValue?: (field: NamePath) => unknown; + getFieldValue: (field: NamePath) => unknown; /** * 获取一组字段名对应的值,当调用 getFieldsValue(true) 时返回所有表单数据 */ - getFieldsValue?: getFieldsValue; + getFieldsValue: getFieldsValue; /** * 重置表单,表单里面没有重置按钮`