-
-
Notifications
You must be signed in to change notification settings - Fork 272
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 warning "cannot be a function" in getValueProps #642
feat: add warning "cannot be a function" in getValueProps #642
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
@@ -578,9 +578,16 @@ class Field extends React.Component<InternalFieldProps, FieldState> implements F | |||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | |||
const originTriggerFunc: any = childProps[trigger]; | |||
|
|||
const valueProps = mergedGetValueProps(value); | |||
|
|||
// warning when prop value is function |
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.
用 process
包一下,免得打包后还会检查。
src/Field.tsx
Outdated
|
||
// warning when prop value is function | ||
Object.keys(valueProps).forEach(key => { | ||
warning(typeof valueProps[key] !== 'function', `cannot return prop value is function in getValueProps (prop name: "${key}")`) |
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.
这个描述比较怪异,它不是不能返回。而是不推荐通过 getValueProps
动态添加 function。
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.
好的👌
src/Field.tsx
Outdated
// warning when prop value is function | ||
if (process.env.NODE_ENV !== 'production') { | ||
Object.keys(valueProps).forEach(key => { | ||
warning(typeof valueProps[key] !== 'function', `Not recommended return prop value is function in getValueProps (prop name: "${key}")`) |
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.
It's not recommended to generate dynamic function prop by
getValueProps
. Please pass it to child component directly.
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.
专业呀
// warning when prop value is function | ||
if (process.env.NODE_ENV !== 'production') { | ||
Object.keys(valueProps).forEach(key => { | ||
warning(typeof valueProps[key] !== 'function', `It's not recommended to generate dynamic function prop by \`getValueProps\`. Please pass it to child component directly (prop: ${key})`) |
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.
一直不知道 warning 第一个参数是 true 打印,还是 false 打印
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.
false hh 我也是看下面代码学的,下面代码也有用 warning 的
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.
所以我倾向
if(xx){
warning(false,'xx')
}
[中文版模板 / Chinese template]
🤔 This is a ...
🔗 Related issue link
关联 PR ant-design/ant-design#46445
关联 issue ant-design/ant-design#46417
💡 Background and solution
根据 #46445 的改动为 getValueProps 的返回值加上一层 warning,判断返回值是否为 function 是 function 则给予提示
📝 Changelog
☑️ Self-Check before Merge