-
-
Notifications
You must be signed in to change notification settings - Fork 271
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: support onLoad #682
feat: support onLoad #682
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
} = (formInstance as InternalFormInstance).getInternalHooks(HOOK_MARK); | ||
|
||
// Pass ref with form instance | ||
React.useImperativeHandle(ref, () => formInstance); | ||
|
||
React.useEffect(() => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
应该不用做 effect,在 useForm(form)
的时候就注册了
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个是 Form 组建的 effect,Form 加载了不要 cb 吗?
src/useForm.ts
Outdated
@@ -119,6 +122,7 @@ export class FormStore { | |||
setPreserve: this.setPreserve, | |||
getInitialValue: this.getInitialValue, | |||
registerWatch: this.registerWatch, | |||
onLoad: this.onLoad, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
API 名字感觉还要在看看。激活态绑定 Form,load 这个不太表意
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我看 context 的名字是 registerForm
当执行 |
{load && ( | ||
<Form | ||
form={form} | ||
// 或者 Form 增加 onLoad? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个感觉比 useForm
更好
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
但是这种的话,感觉直接 HOC 个 Form,在 mount effect 里自己拓展就行了
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const MyForm = ({ onLoad, ...props }) => {
useEffect(() => {
onLoad?.();
}, []);
return <Form {...props} />
};
对于加载重置,看起来也是 HOC 即可: const AutoResetForm = ({ form, ...props }) => {
useEffect(() => {
form.resetFields();
}, []);
return <Form form={form} {...props} />
}; |
ref ant-design/ant-design#48308