简体   繁体   中英

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

I am writing this code and import React and Component in app/js file and also try to import app.js to index.js . but I get this error ' 'React' must be in scope when using JSX in 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'));

I got this error

./src/index.js Line 6:'React' must be in scope when using JSX react/react-in-jsx-scope

You are using JSX in here ( <App /> ):

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

Whenever you use JSX React should be in scope.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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