我是一个Angular开发者,对React还不熟悉,这是一个简单的React组件,但是不起作用。
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;
错误: 在使用JSX时,'React'必须在作用域内 react/react-in-jsx-scope
在
.eslintrc.js
/.eslintrc.json
中添加以下设置以忽略这些错误:为什么? 如果您使用的是
NEXT.js
,则无需在文件顶部导入React
,nextjs会为您完成。参考:https://gourav.io/blog/nextjs-cheatsheet(Next.js速查表)
导入行应该是:
注意React的大写R。