[英]How do I resolve eslint conflict between props and module imports with the same name?
I'm using react with react-redux and eslint . 我正在使用react -redux和eslint的react 。 In my container, I import an action that will be bound to the component's props in mapDispatchToProps like so:
在我的容器中,导入一个将绑定到mapDispatchToProps中组件的props的动作,如下所示:
// simplified for brevity
import { getGames } from '../actions/game';
const mapDispatchToProps = dispatch => ({
getGames: () => dispatch(getGames())
});
class App extend React.Component {
// class members
}
export default App connect(mapDispatchToProps)(App);
I call getGames in componentDidMount: 我在componentDidMount中调用getGames:
componentDidMount () {
const { getGames } = this.props;
getGames().then(json => console.log(json));
}
Eslint insists that I use object destructuring to pull values from this.props in componentDidMount, which is fine. Eslint坚持认为我使用对象分解来从componentDidMount中的this.props中获取值,这很好。
The problem is, eslint also complains that getGames is already declared in the outer scope (the import statement) when I do use object destructuring. 问题是,eslint还抱怨当我使用对象分解时,已经在外部范围(import语句)中声明了getGames。
I'd like to appese eslint in both cases, but can't think of how I'd use object destructing in both the import and the this.props destructure without causing a naming conflict. 在这两种情况下,我都想保留一下,但是想不出在导入和 this.props分解中如何使用对象分解,而不会引起命名冲突。
Any ideas are much appreciated! 任何想法都非常感谢!
// simplified for brevity
import { getGames } from '../actions/game';
you can use alias for it. 您可以使用别名。
import { getGames as getGames1 } from '../actions/game';
and use alias instead. 并改用别名。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.