From 0adfa6cf524328d71f02dff6e976a85d0236872c Mon Sep 17 00:00:00 2001 From: crazyair <645381995@qq.com> Date: Wed, 24 Apr 2024 17:38:48 +0800 Subject: [PATCH] feat: test --- docs/examples/reload.tsx | 11 ++++++++--- src/Form.tsx | 6 ++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/docs/examples/reload.tsx b/docs/examples/reload.tsx index a4cb5ee2..1f9a87aa 100644 --- a/docs/examples/reload.tsx +++ b/docs/examples/reload.tsx @@ -7,9 +7,9 @@ export default () => { const [count, setCount] = useState(0); const [form] = Form.useForm(undefined, { + // useForm 增加 onLoad 还是 Form 增加 onLoad onFormLoad: () => { - console.log('load'); - form.resetFields(); + // form.resetFields(); }, }); @@ -26,7 +26,12 @@ export default () => { load {load && ( -
+ form.resetFields()} + initialValues={{ count }} + > diff --git a/src/Form.tsx b/src/Form.tsx index 86867738..323d2336 100644 --- a/src/Form.tsx +++ b/src/Form.tsx @@ -33,6 +33,7 @@ export interface FormProps extends BaseFormProps { onFinishFailed?: Callbacks['onFinishFailed']; validateTrigger?: string | string[] | false; preserve?: boolean; + onLoad?: () => void; } const Form: React.ForwardRefRenderFunction = ( @@ -50,6 +51,7 @@ const Form: React.ForwardRefRenderFunction = ( onFieldsChange, onFinish, onFinishFailed, + onLoad, ...restProps }: FormProps, ref, @@ -76,6 +78,10 @@ const Form: React.ForwardRefRenderFunction = ( onFormLoad(); }, [onFormLoad]); + React.useEffect(() => { + onLoad(); + }, [onLoad]); + // Register form into Context React.useEffect(() => { formContext.registerForm(name, formInstance);