繁体   English   中英

导入组件时使用 JSX 错误时,get React' 必须在范围内

[英]get React' must be in scope when using JSX error when import component

我正在编写此代码并在app/js文件中导入ReactComponent ,并尝试将 app.js 导入index.js 但我收到此error “在index.js使用JSX时必须在范围内”

应用程序.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;

索引.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 都应该在范围内。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM