简体   繁体   English

“反应”不适用于全球范围

[英]'React' does not work from global scope

I cannot figure out what is I'm making wrong. 我无法弄清楚我在做什么错。 Also I had read a several questions on the SOF, but any of them is do not suits me. 我也已经阅读了关于SOF的几个问题,但是其中任何一个都不适合我。

I have a stack of errors: 我有很多错误:

Line 3: 'React' must be in scope when using JSX react/react-in-jsx-scope 第3行:使用JSX react / react-in-jsx-scope时,“ React”必须在范围内
Line 4: 'React' must be in scope when using JSX react/react-in-jsx-scope 第4行:使用JSX react / react-in-jsx-scope时,“ React”必须在范围内
Line 5: 'React' must be in scope when using JSX react/react-in-jsx-scope 第5行:使用JSX react / react-in-jsx-scope时,“ React”必须在范围内
Line 9: 'ReactDOM' is not defined no-undef 第9行:未定义'ReactDOM'no-undef

 function tick() { const element = ( <div> <h1>Hello, world!</h1> <h2>It is {new Date().toLocaleTimeString()}.</h2> </div> ); ReactDOM.render(element, document.getElementById('root')); } setInterval(tick, 1000); 
 <script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react-dom.min.js"></script> 

Add

import React from 'react'
import ReactDOM from 'react-dom'

in the top of the file. 在文件顶部。

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

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