首页 > 解决方案 > 在不更改配置的情况下获取过去的 import/no-named-as-default lint 错误

问题描述

我收到 no-named-as-default eslint 错误。
遇到需要 Redux 功能的问题,我不能只使用命名导入。

在这里看到了类似的查询,但它们都涉及配置更改,例如修改 eslint 文件
或与 Babel 配置有关的事情。
示例:如何解决 eslint import/no-named-as-default

有没有办法在代码本身中实现它?

因为我无法更改任何配置。我可以一起放弃默认导入并使用
2x 命名导入(也许 1 带有别名?)。

但我似乎无法摆脱默认。当我删除它时,底部出口会抱怨。
如果组件上没有默认导入,也不确定 eslint 是否会开始抱怨。

如果我将其作为默认值导入,这就是 eslint 抱怨的组件。

export const IndicatorPage = ({setData}) => {
    // logic
}

const mapDispatchToProps = {
  setData: setIndicatorData
}

// ide complains if I remove this default. Plus even if I could drop default, 
// wondering if that would be another lint error for not having defaults 
export default connect(null, mapDispatchToProps)(IndicatorPage);

当我将其导入另一个组件时的示例。
这让 eslint 很高兴,但它破坏了我的 redux 功能。

import { IndicatorPage } from './IndicatorPage';

这使得 Redux 正常工作,但现在 eslint 抱怨......

import IndicatorPage from './IndicatorPage';

标签: javascriptreactjs

解决方案


推荐阅读