[英]Line 4:13: 'React' is not defined no-undef
当我想创建一个没有 JSX 的元素时,它会显示这个错误'React' is not defined no-undef
。 我是初学者。 我不知道是什么问题。 谁能帮忙
import logo from './logo.svg';
import './App.css';
const app = React.createElement("h1", null, "Without JSX"); // Showing an error
function App() {
return (
<div className="App">
{app};
</div>
);
}
export default App;
这些消息显示在 VS 代码终端中。
Failed to compile.
./src/index.js
SyntaxError: E:\react_js_course\src\index.js: Unexpected token, expected "," (11:2)
Failed to compile.
src\App.js
Line 4:13: 'React' is not defined no-undef
Search for the keywords to learn more about each error.
仅基于您提供的代码的几点:
您在示例中使用 JSX:您的App
组件返回 JSX,因此React
应该在 scope 中执行此操作。
您正在显式使用 React 方法createElement
,因此React
应该在此文件中可用。
要解决这两个问题,请添加import React from 'react';
在这个文件的顶部。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.