javascript - 导入组件时使用 JSX 错误时,get React' 必须在范围内
问题描述
我正在编写此代码并在文件中导入React
和并尝试将 app.js 导入到. 但我得到这个''React'在使用时必须在范围内Component
app/js
index.js
error
JSX
index.js
应用程序.js:
import React ,{Component} from 'react';
class App extends Component{
constructor(props){
super(props);
}
render(){
return (
<div>
<h1>Hello Ashkan</h1>
</div>
);
}
}
export default App;
index.js
import ReactDOM from 'react-dom';
import App from './app'
ReactDOM.render(<App/>,document.getElementById('root'));
我收到了这个错误
./src/index.js 第 6 行:使用 JSX react/react-in-jsx-scope 时,'React' 必须在范围内
解决方案
您在这里使用 JSX ( <App />
):
ReactDOM.render(<App/>,document.getElementById('root'));
每当你使用 JSX 时,React 都应该在范围内。
推荐阅读
- c++ - 如何以非常精细的分辨率测量持续时间?
- unit-testing - 如何让詹金斯在多个核心上构建?
- .net - 如何将来自 QueryHelpers.AddQueryString() 的字符串 url 用于 dot net core 2.1 中的 Api 控制器中的 HttpPost Api
- java - Maven 导入在 IntelliJ 中创建重复类
- python - Pandas 有条件地创建数据框列:基于多个条件
- python - 如何为 Python 3.7 安装 PyVimeo?
- javascript - 我想在我的 React 应用程序中添加一个文本框,我该怎么做?
- javascript - 从 JSON 数组中删除重复对象
- firebase - FirebaseError:无效的流令牌
- c# - 在构造函数中创建新实例时模拟 HttpClient