Skip to content

Commit

Permalink
feat: test
Browse files Browse the repository at this point in the history
  • Loading branch information
crazyair committed Apr 24, 2024
1 parent 0f949bf commit 0adfa6c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
11 changes: 8 additions & 3 deletions docs/examples/reload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
},
});

Expand All @@ -26,7 +26,12 @@ export default () => {
load
</button>
{load && (
<Form form={form} initialValues={{ count }}>
<Form
form={form}
// 或者 Form 增加 onLoad?
onLoad={() => form.resetFields()}
initialValues={{ count }}
>
<Field name="count">
<Input placeholder="count" />
</Field>
Expand Down
6 changes: 6 additions & 0 deletions src/Form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export interface FormProps<Values = any> extends BaseFormProps {
onFinishFailed?: Callbacks<Values>['onFinishFailed'];
validateTrigger?: string | string[] | false;
preserve?: boolean;
onLoad?: () => void;
}

const Form: React.ForwardRefRenderFunction<FormInstance, FormProps> = (
Expand All @@ -50,6 +51,7 @@ const Form: React.ForwardRefRenderFunction<FormInstance, FormProps> = (
onFieldsChange,
onFinish,
onFinishFailed,
onLoad,
...restProps
}: FormProps,
ref,
Expand All @@ -76,6 +78,10 @@ const Form: React.ForwardRefRenderFunction<FormInstance, FormProps> = (
onFormLoad();
}, [onFormLoad]);

React.useEffect(() => {
onLoad();
}, [onLoad]);

// Register form into Context
React.useEffect(() => {
formContext.registerForm(name, formInstance);
Expand Down

0 comments on commit 0adfa6c

Please sign in to comment.