简体   繁体   English

如何解决道具和同名模块导入之间的eslint冲突?

[英]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 -reduxeslint的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.

相关问题 eslint导入webpack:无法解析模块路径 - eslint imports in webpack: Unable to resolve path to module 如何在本机中解决模块名称冲突 - How to resolve module name conflict in react native 我如何更改eslint解决设置 - How I can change eslint resolve settings 如何执行 function 作为 React 组件之间的道具传递? - How do I execute a function passed as props between components in React? 指向分支时如何解决“找不到模块”? - How do I resolve “Cannot find module” when pointing to a branch? eslint:无法解析模块“src/interfaces”的路径 - eslint: Unable to resolve path to module 'src/interfaces' 在开发中运行反应项目时,我在 eslint 配置和基本配置之间遇到冲突错误 - I am having a conflict error between eslint configuation and base configuration when running a react project in development 如何从道具中取消引用具有相同名称的值 - How to dereference values with same name from props 如何解决使用“儿童”作为道具的 ReactMarkDown 错误不要将儿童作为道具传递 - How can I resolve ReactMarkDown that uses "children" as a prop w/ Error Do not pass children as props 如何忽略 Next.js 组件中的 CSS 模块导入导致单元测试中的解析错误 - How do I ignore CSS Module imports in a Next.js component that cause parse errors in unit tests
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM