Skip to content
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

Closed
wants to merge 9 commits into from

Conversation

crazyair
Copy link
Contributor

@crazyair crazyair commented Apr 24, 2024

Copy link

vercel bot commented Apr 24, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
field-form ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 24, 2024 9:55am

} = (formInstance as InternalFormInstance).getInternalHooks(HOOK_MARK);

// Pass ref with form instance
React.useImperativeHandle(ref, () => formInstance);

React.useEffect(() => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

应该不用做 effect,在 useForm(form) 的时候就注册了

Copy link
Contributor Author

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,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

API 名字感觉还要在看看。激活态绑定 Form,load 这个不太表意

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我看 context 的名字是 registerForm

@crazyair crazyair changed the title Support onLoad support onLoad Apr 24, 2024
@crazyair crazyair changed the title support onLoad feat: support onLoad Apr 24, 2024
@crazyair
Copy link
Contributor Author

当执行 form.resetFields(); 后,卸载 Form 组建后,再执行 form.getFieldsValue(true) 还能获取到 表单的值,这个是不能满足需求都,需要增加一个方法 form.clear() 清理数据

{load && (
<Form
form={form}
// 或者 Form 增加 onLoad?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个感觉比 useForm 更好

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

但是这种的话,感觉直接 HOC 个 Form,在 mount effect 里自己拓展就行了

Copy link
Member

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} />
};

@zombieJ
Copy link
Member

zombieJ commented May 9, 2024

对于加载重置,看起来也是 HOC 即可:

const AutoResetForm = ({ form, ...props }) => {
  useEffect(() => {
    form.resetFields();
  }, []);

  return <Form form={form} {...props} />
};

@crazyair crazyair closed this May 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants