【发布时间】:2017-06-19 13:05:14
【问题描述】:
我是 reactjs 的新手。我创建了一个应用程序并尝试在 app.js 中加载标头组件。当我尝试加载 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? -
你想试试“从'./components/Header'导入标题”吗?如果是,我已经只使用 Header。
-
是的,这就是问题所在:您导入它但从不使用它。将其添加到渲染函数的返回值中。
-
export default class Header extends React.Component { }然后您必须将文件导入到要返回值的实际文件中。 -
@Ozan - 完美运行。非常感谢。
标签: javascript reactjs ecmascript-6 es6-module-loader