【发布时间】:2020-01-11 22:07:52
【问题描述】:
我正在编写此代码并在app/js 文件中导入React 和Component,并尝试将app.js 导入index.js。但我得到这个error ''React' 必须在JSX 中使用index.js 时在范围内
app.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' 必须在作用域内
【问题讨论】:
-
React 仍然需要在
index.js中导入 -
import React from 'react' import react like this in index.js
-
查看错误来自哪个文件...
-
很抱歉这是我的问题。感谢您的帮助
标签: javascript reactjs