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: add wrappedComponentRef and deprecate withRef #87

Merged
merged 1 commit into from
Jun 13, 2017
Merged

Conversation

benjycui
Copy link
Member

No description provided.

// deprecated
const EnhancedForm = createForm({ withRef: true })(Form);
<EnhancedForm ref="form" />
this.refs.form.refs.wrappedComponent // => The instance of Form
Copy link
Member Author

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

Choose a reason for hiding this comment

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

wrappedComponentRef 直接指向我们希望暴露给用户的节点,使用方便,并且与组件层级无关,非常稳定。

Copy link
Member

Choose a reason for hiding this comment

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

this.formRef 一般用在什么地方?

Copy link
Member Author

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()

Copy link
Member

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。

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling edfe6c3 on feat-ref into ** on master**.

@benjycui benjycui merged commit 1aa242d into master Jun 13, 2017
@benjycui benjycui deleted the feat-ref branch June 13, 2017 08:59
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.

4 participants