【问题标题】:WebStorm doesn't recognise use of components inside JSXWebStorm 无法识别 JSX 中组件的使用
【发布时间】:2018-07-23 20:56:17
【问题描述】:

假设我正在导入一个组件:

const MyComponent   = require('./components/MyComponent');

然后在 JSX 块中使用它:

const App = props => (<MyComponent/>)

我在 WebStorm 中收到来自 Eslint 的错误:

'MyComponent' is assigned a value but never used (no-unused-vars)

如何让 WebStorm 理解我正在使用这个变量?

【问题讨论】:

  • Require 通常用于平面文件加载。您应该改用import MyComponent from './components/MyComponent'。试试看:)
  • @cbll 使用时同样的错误:)

标签: reactjs react-native webstorm jsx eslint


【解决方案1】:

不是 WebStorm 而是 ESLint 无法识别您的 JSX 变量。你安装了 eslint-plugin-react 吗?我猜你错过了jsx-uses-vars 规则。一些提示见https://github.com/eslint/eslint/issues/2156,https://github.com/hyperapp/hyperapp/issues/557

【讨论】:

  • @Iena 谢谢!现在没有错误,但现在我得到“未使用的常量 MyComponent”
  • 我也收到“未使用的常量...”警告,不是来自我的 linting 配置,而是来自 WebStorm 本身。
猜你喜欢
  • 2018-07-13
  • 2014-07-18
  • 2016-05-20
  • 1970-01-01
  • 2017-09-05
  • 2016-12-25
  • 2016-02-02
  • 1970-01-01
相关资源
最近更新 更多