When using 'React' in JSX, it must be included in the scope react/react-in-jsx-scope
P粉364642019
P粉364642019 2023-09-18 19:58:41
0
2
670

I am an Angular developer and new to React. This is a simple React component, but it doesn't work.

import react, { Component } from 'react';
import { render } from 'react-dom';

class TechView extends Component {

    constructor(props){
       super(props);
       this.state = {
           name:'Gopinath'
       }
    }
    render(){
        return(
            <span>hello Tech View</span>
        );
    }
}

export default TechView;

mistake: When using JSX, 'React' must be in scope react/react-in-jsx-scope

P粉364642019
P粉364642019

reply all(2)
P粉953231781

Add the following settings in .eslintrc.js / .eslintrc.json to ignore these errors:

rules: {
    // suppress errors for missing 'import React' in files
   "react/react-in-jsx-scope": "off",
    // allow jsx syntax in js files (for next.js project)
   "react/jsx-filename-extension": [1, { "extensions": [".js", ".jsx"] }], //should add ".ts" if typescript project
  }

Why? If you are using NEXT.js, there is no need to import React at the top of the file, nextjs will do it for you.

Reference: https://gourav.io/blog/nextjs-cheatsheet(Next.js cheatsheet)

P粉183077097

The import line should be:

import React, { Component }  from 'react';

Note the capital R in React.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template