gpt4 book ai didi

javascript - 已定义“ header ”但从未使用过 no-unused-vars

转载 作者:行者123 更新时间:2023-12-03 04:04:11 26 4
gpt4 key购买 nike

我是reactjs新手。我创建了一个应用程序并尝试在 app.js 中加载 header 组件。当我尝试加载 header 组件时,它在命令提示符中显示抛出警告错误,如

./src/components/Header.jsx
Line 2 'Header' is defined but never used no-unused-vars

当我运行应用程序时,也会在浏览器中引发错误

React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in.

在 App.js:24 检查您的代码

我在根目录中添加了一个文件“.eslintrc”,并向其中添加了以下代码

{
"parserOptions": {
"ecmaFeatures": {
"jsx": true
}
},
"rules": {

}
}

到目前为止,没有任何效果。谁能帮我解决这个问题吗?

最佳答案

请将Header.jsx重命名为Header.js

请务必将以下代码行放在您的 App.js 之上:

import {Header} from '/src/components/Header.jsx'

务必将export放在class Header {..}

希望有帮助;-)

关于javascript - 已定义“ header ”但从未使用过 no-unused-vars,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44631405/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com