-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
React规范中强制defaultProps的规则跟redux的冲突 #40
Comments
这些属性应该是required的,这个规则只会检查optional的属性有没有默认值
…--
Gray Zhang
在 2017年5月25日 at 下午6:54:40, ralph-cheng ([email protected]) 写到:
当一个组件是react-redux connect来的,就会有若干来自store state的props,这些props的默认值是写在reducer
function的参数列表里的,(甚至可能是根据若干store state值计算出来的)。
const error = (state = null, action) => {
switch (action.type) {
case 'Fail':
return action.error;
default:
return state;
}
}
这时已经不适合在组件代码的defaultProps里再写一遍默认值,如果根据业务逻辑,用到该store
state值的prop不是必需,就与这条规范准则冲突了。
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#40>, or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAnCPfNQyXvE-05XcDAuK1j4huHa7PmUks5r9V3wgaJpZM4NmPm->
.
|
现在有遇到业务上是optional但connect的情况吗,想看个例子
…--
Gray Zhang
在 2017年5月25日 at 下午7:13:23, Gray Zhang ([email protected]) 写到:
这些属性应该是required的,这个规则只会检查optional的属性有没有默认值
--
Gray Zhang
在 2017年5月25日 at 下午6:54:40, ralph-cheng ***@***.***) 写到:
> 当一个组件是react-redux connect来的,就会有若干来自store
> state的props,这些props的默认值是写在reducer function的参数列表里的,(甚至可能是根据若干store
> state值计算出来的)。
>
> const error = (state = null, action) => {
> switch (action.type) {
> case 'Fail':
> return action.error;
> default:
> return state;
> }
> }
>
> 这时已经不适合在组件代码的defaultProps里再写一遍默认值,如果根据业务逻辑,用到该store
> state值的prop不是必需,就与这条规范准则冲突了。
>
> —
> You are receiving this because you are subscribed to this thread.
> Reply to this email directly, view it on GitHub
> <#40>, or mute the thread
> <https://github.com/notifications/unsubscribe-auth/AAnCPfNQyXvE-05XcDAuK1j4huHa7PmUks5r9V3wgaJpZM4NmPm->
> .
>
|
你是说所有connect来的属性都要是required吗?要不然必然会与这条规则冲突,如果这样,既不符合组件本身逻辑,又会凭空多写很多 业务中的例子就是ajax请求的error message,对于页面组件本身而已,error没必要是required。Ajax请求是mapDispatchToProps里dispatch的async action,请求状态处理也是通过dispatch 相应action做的,这些状态(错误)自然会落到store里去。 |
我们等待一下这个Issue的官方回复再决定怎么做:jsx-eslint/eslint-plugin-react#1224 |
参考那边的意见,我也觉得在 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
当一个组件是react-redux connect来的,就会有若干来自store state的props,这些props的默认值是写在reducer function的参数列表里的,(甚至可能是根据若干store state值计算出来的)。
这时已经不适合在组件代码的
defaultProps
里再写一遍默认值,如果根据业务逻辑,用到该store state值的prop不是必需,就与这条规范准则冲突了。The text was updated successfully, but these errors were encountered: