【问题标题】:get React' must be in scope when using JSX error when import component导入组件时使用 JSX 错误时,get React' 必须在范围内
【发布时间】: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' 必须在作用域内

【问题讨论】:

标签: javascript reactjs


【解决方案1】:

你在这里使用 JSX (&lt;App /&gt;):

ReactDOM.render(<App/>,document.getElementById('root'));

无论何时使用 JSX,React 都应该在范围内。

【讨论】:

    猜你喜欢
    • 2023-01-21
    • 2017-07-27
    • 2022-11-17
    • 2020-09-11
    • 2019-10-26
    • 2018-08-22
    • 2018-08-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多