简体   繁体   English

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

[英]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 .我正在编写此代码并在app/js文件中导入ReactComponent ,并尝试将 app.js 导入index.js but I get this error ' 'React' must be in scope when using JSX in index.js但我收到此error “在index.js使用JSX时必须在范围内”

app.js :应用程序.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索引.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 ./src/index.js 第 6 行:使用 JSX react/react-in-jsx-scope 时,'React' 必须在作用域内

You are using JSX in here ( <App /> ):您在这里使用 JSX ( <App /> ):

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

Whenever you use JSX React should be in scope.每当您使用 JSX 时,React 都应该在范围内。

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

相关问题 错误:使用 JSX 时,“React”必须在 scope 中 - Error: 'React' must be in scope when using JSX 使用 JSX 时,必须在 scope 中获取“反应” - Getting 'React' must be in scope when using JSX create-react-app 和 TypeScript 错误:使用 JSX 时“React”必须在范围内 - create-react-app and TypeScript error: 'React' must be in scope when using JSX 教程代码-&gt;使用JSX时,“反应”必须在范围内 - tutorial code -> 'React' must be in scope when using JSX 使用 jsx 时,我面临的反应必须在范围内,这是错误的 tyoe ......? - i am facing react must be in scope when using jsx this tyoe of error…? 运行已编译的JSX时发生React Reflux错误,但使用Transformer时不发生 - React Reflux error when running compiled JSX but not when using transformer 在声明的内联中导入时使用相同的JSX组件时出错 - Error using the same JSX Component when imported on declared inline 添加第二个时,React JSX 表达式必须有父元素错误<div> - React JSX expressions must have a parent element error when adding a second <div> 尝试渲染反应组件时,未定义“名称框”反应/jsx-no-undef 错误 - Getting 'Namebox' is not defined react/jsx-no-undef error when trying to render a react Component 在需要时导入反应组件 - Import react component when needed
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM