这是.eslintrc.json
文件中对于eslint的配置:
{
"env": {
"browser": true,
"commonjs": true,
"es6": true
},
"extends": "eslint:recommended",
"parserOptions": {
"ecmaVersion": 6,
"ecmaFeatures": {
"experimentalObjectRestSpread": true,
"jsx": true
},
"sourceType": "module"
},
"plugins": [
"react"
],
"rules": {
"react/jsx-uses-react": "error",
"react/jsx-uses-vars": ["error"],
"indent": 0,
"linebreak-style": [
"error",
"windows"
],
"quotes": [
"error",
"single"
],
"semi": [
"error",
"always"
]
},
"settings": {
"react": {
"pragma": "React",
"version": "15.0"
}
}
}
这是下面反应工作区的app.jsx
:
import React, { Component } from 'react';
class App extends React.Component {
render () {
return(
<h1>Hello Newbies</h1>
);
}
}
export default App;
我从eslint 'Component' is defined but never used.
收到错误我无法通过做任何事情来解决这个问题,而是挖掘网络。我该如何解决这个错误?非常感谢帮助。
答案 0 :(得分:3)
尝试
class App extends Component {
答案 1 :(得分:1)
选项1: 由于您扩展了React.component并且已经导入了React,因此您不需要导入{Component}。
选项2: 您可以使用Component而不是React.Component扩展您的应用程序