[英]How to fix "Component is defined but never used" for eslint in react?
This is the config i have for eslint in .eslintrc.json
file:这是我在
.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"
}
}
}
This is the app.jsx
from the react workspace below:这是下面反应工作区中的
app.jsx
:
import React, { Component } from 'react';
class App extends React.Component {
render () {
return(
<h1>Hello Newbies</h1>
);
}
}
export default App;
I am getting error from eslint 'Component' is defined but never used.
我从 eslint 收到错误
'Component' is defined but never used.
I can not fix this by doing anything so far but digging the web.到目前为止,我无法通过挖掘 web 来解决此问题。 How can i fix this error?
我该如何解决这个错误? Help would be very much appreciated.
帮助将不胜感激。
尝试
class App extends Component {
Option 1: You don't need to import {Component} since you extends React.component and React is already imported. 选项1:您不需要导入{Component},因为您扩展了React.component且React已经被导入。
Option 2: You can extend your App with Component instead of React.Component 选项2:您可以使用Component而不是React.Component扩展您的App
Just remove "import React, { Component } from 'react';"只需删除“import React, { Component } from 'react';” this line and warning will be resolved as this will be not used in functional based Components.
此行和警告将得到解决,因为这不会在基于功能的组件中使用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.