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

chore: clear any #684

Merged
merged 6 commits into from
Apr 30, 2024
Merged

chore: clear any #684

merged 6 commits into from
Apr 30, 2024

Conversation

li-jia-nan
Copy link
Member

Copy link

vercel bot commented Apr 30, 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 30, 2024 8:01am

Copy link

codecov bot commented Apr 30, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.43%. Comparing base (029abbb) to head (6459cdd).
Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #684   +/-   ##
=======================================
  Coverage   99.43%   99.43%           
=======================================
  Files          18       18           
  Lines        1247     1247           
  Branches      308      304    -4     
=======================================
  Hits         1240     1240           
  Misses          7        7           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

src/Field.tsx Outdated
@@ -562,11 +557,11 @@ class Field extends React.Component<InternalFieldProps, FieldState> implements F
public getControlled = (childProps: ChildProps = {}) => {
const {
name,
trigger,
trigger = 'onChange',
Copy link
Member

Choose a reason for hiding this comment

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

这不等价吧,class component 的默认值只有 defaultProps 这个统一入口,去掉之后每次从 this.props 取都需要给默认值

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.props.trigger

Copy link
Member

Choose a reason for hiding this comment

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

不利于维护

Copy link
Member Author

Choose a reason for hiding this comment

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

我去年把 antd 所有的 defaultProps 都改成默认值了,就差这里了

Copy link
Member

Choose a reason for hiding this comment

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

antd 都是 FC,不用 defaultProps 的

Copy link
Member

Choose a reason for hiding this comment

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

https://react.dev/reference/react/Component#static-defaultprops
没说废弃吧,和 Component 一起放在 legacy api 里

Copy link
Member Author

Choose a reason for hiding this comment

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

啊,legacy api 不就可以慢慢干掉了么😕

Copy link
Member

@MadCcc MadCcc Apr 30, 2024

Choose a reason for hiding this comment

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

这样理解:

  1. defaultProps 在 class component 下没有说明废弃,也没有更好的替代方案
  2. 整个 Component API 是 legacy,要干掉是一起干掉
    放在一起就是说明 Component API 是这么用的

Copy link
Member

Choose a reason for hiding this comment

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

那我上面那个 hook 可以统一入口

Component 用不了 hook 哦

Copy link
Member Author

Choose a reason for hiding this comment

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

好,我改回去了

src/Field.tsx Show resolved Hide resolved
@li-jia-nan li-jia-nan changed the title chore: rm defaultProps chore: clear any Apr 30, 2024
@MadCcc MadCcc merged commit 45cc9fa into master Apr 30, 2024
11 checks passed
@delete-merged-branch delete-merged-branch bot deleted the rm-defaultProps branch April 30, 2024 08:04
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.

3 participants