简体   繁体   English

组件已定义但从未使用 reactjs 中的 no-unused-vars 错误警告

[英]component is defined but never used no-unused-vars error warning in reactjs

在此处输入图像描述

import React from "react";
import navBar from "./components/navBar/navBar"; //navBar is imported here

function App() {
  return (
    <>
      <div className="App">
        <navBar /> //navBar is used here
      </div>
    </>
  );
}

export default App;

I changed the eslint.我改变了eslint。 But no use and tried some stackoverflow solutions but no change.但没有用并尝试了一些 stackoverflow 解决方案但没有改变。

In JSX, lower-case tag names are considered to be HTML tags.在 JSX 中,小写的标签名称被认为是 HTML 标签。

So you can change the component name to NavBar, or while importing you can write import NavBar from "./components/navBar/navBar"; //navBar is imported here因此,您可以将组件名称更改为 NavBar,或者在导入时您可以编写import NavBar from "./components/navBar/navBar"; //navBar is imported here import NavBar from "./components/navBar/navBar"; //navBar is imported here

install npm install --save-dev eslint-plugin-react.安装npm install --save-dev eslint-plugin-react.

Then, add this to .eslintrc.json , under extends然后,将其添加到.eslintrc.json的 extends 下

'extends': [
    'plugin:react/recommended'
]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 定义了“ stringValues”,但从未使用过no-unused-vars - “stringValues” is defined but never used no-unused-vars 定义了“标头”,但从未使用过未使用的变量 - 'Header' is defined but never used no-unused-vars &#39;Home&#39; 已定义但从未使用 no-unused-vars&quot;.* - 'Home' is defined but never used no-unused-vars".* &#39;UserInput&#39; 已定义但从未使用过 no-unused-vars &#39;UserOutput&#39; 已定义但从未使用过 no-unused-vars - 'UserInput' is defined but never used no-unused-vars 'UserOutput' is defined but never used no-unused-vars 如何解决“错误'Vote'已定义但从未使用(no-unused-vars)”的问题? - How to solve the problem “error 'Vote' is defined but never used ( no-unused-vars)”? @typescript-eslint/eslint-plugin 错误:定义了“路由”但从未使用过(no-unused-vars) - @typescript-eslint/eslint-plugin error: 'Route' is defined but never used (no-unused-vars) 为使用的var编译警告no-unused-vars - Compile warning no-unused-vars for vars that are used 11:5 错误“路由器”被分配了一个值,但从未使用过 no-unused-vars - 11:5 error 'router' is assigned a value but never used no-unused-vars src\\App.js &#39;nav&#39; 已定义但从未使用过 no-unused-vars - src\App.js 'nav' is defined but never used no-unused-vars &#39;inStock&#39; 被赋值但从未使用过 no-unused-vars - 'inStock' is assigned a value but never used no-unused-vars
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM