-
Notifications
You must be signed in to change notification settings - Fork 296
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: add wrappedComponentRef and deprecate withRef #87
Conversation
// deprecated | ||
const EnhancedForm = createForm({ withRef: true })(Form); | ||
<EnhancedForm ref="form" /> | ||
this.refs.form.refs.wrappedComponent // => The instance of 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.
withRef
这种 API 使用起来麻烦,并且非常不稳定,因为依赖于组件层级。
// Recommended | ||
const EnhancedForm = createForm()(Form); | ||
<EnhancedForm wrappedComponentRef={(inst) => this.formRef = inst} /> | ||
this.formRef // => The instance of 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.
wrappedComponentRef
直接指向我们希望暴露给用户的节点,使用方便,并且与组件层级无关,非常稳定。
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.
this.formRef
一般用在什么地方?
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.
比如外层组件重置表单 this.formRef.props.form.resetFields()
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.
感觉是 anti-pattern ,外层组件如果有 reset 的行为,那么它应该包装成 rc-form 组件,然后把 props.form 传给内层表单 UI。
Changes Unknown when pulling edfe6c3 on feat-ref into ** on master**. |
No description provided.