【发布时间】:2019-02-04 21:25:28
【问题描述】:
使用 ESLing 插件进行反应我在解构和道具类型验证方面感到困惑。 在下面的课堂上
class Game extends Component {
componentWillMount() {
this.props.createNewPlayer(); // Must use destructuring props assignment (react/destructuring-assignment)
}
render() {
const { players } = this.props; // 'players' is missing in props validation (react/prop-types)
const count = Object.keys(players).length;
return (...);
}
}
GameInit.propTypes = {createNewPlayer: PropTypes.func.isRequired};
const mapStateToProps = state => ({players: state.players});
export default connect(mapStateToProps,{ createNewPlayer })(Game);
所以如果我将第一部分的结构重写为
componentWillMount() {
const {createNewPlayer}=this.props; // 'createNewPlayer' is already declared in the upper scope. (no-shadow)
createNewPlayer();
}
如果我将proptypes重写为播放器的解构
GameInit.propTypes = {
createNewPlayer: PropTypes.func.isRequired,
players: PropTypes.object.isRequired, // Prop type `object` is forbidden (react/forbid-prop-types)
};
这里遵循 ESLint 规则的正确方法是什么?不改变.eslintrc中的规则
【问题讨论】:
-
同时禁用复杂对象的行作品。 // eslint-disable-line [规则名称]
标签: reactjs react-redux eslint eslint-config-airbnb