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

React规范中强制defaultProps的规则跟redux的冲突 #40

Open
ralph-cheng opened this issue May 25, 2017 · 5 comments
Open

React规范中强制defaultProps的规则跟redux的冲突 #40

ralph-cheng opened this issue May 25, 2017 · 5 comments

Comments

@ralph-cheng
Copy link

当一个组件是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不是必需,就与这条规范准则冲突了。

@otakustay
Copy link
Member

otakustay commented May 25, 2017 via email

@otakustay
Copy link
Member

otakustay commented May 25, 2017 via email

@ralph-cheng
Copy link
Author

你是说所有connect来的属性都要是required吗?要不然必然会与这条规则冲突,如果这样,既不符合组件本身逻辑,又会凭空多写很多isRequired

业务中的例子就是ajax请求的error message,对于页面组件本身而已,error没必要是required。Ajax请求是mapDispatchToProps里dispatch的async action,请求状态处理也是通过dispatch 相应action做的,这些状态(错误)自然会落到store里去。

@otakustay
Copy link
Member

我们等待一下这个Issue的官方回复再决定怎么做:jsx-eslint/eslint-plugin-react#1224

@otakustay
Copy link
Member

参考那边的意见,我也觉得在container(s)目录下放一个.fecsrc文件比较合适

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

No branches or pull requests

2 participants