const { createElement} = React
const { render } = ReactDOM
const title = createElement(
'h1',
{id: 'title', className: 'header'},
'Hello World'
)
render(
title,
document.getElementById('react-container')
)
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<script src="https://facebook.com/react-15.1.0.js"></script>
<script src="https://facebook.com/react-dom-15.1.0.js"></script>
<meta charset="UTF-8">
<title>Hello World with React</title>
</head>
<body>
<div id = "react-container"></div>
<script src = "index.js"></script>
</body>
</html>
当我输入代码时,将不会加载本地host:3000服务器。它说React是不确定的。 Here is what I'm talking about我需要安装一些东西吗?我已经安装了node.js,并且正在使用它,所以我有点困惑。谢谢!
P.S-我在原始脚本中使用了fb.me,但不得不将其更改为facebook.com。
答案 0 :(得分:1)
似乎这些*.js
链接已损坏或无效。
您可以使用其他CDN(例如UNPKG或cloudflare),如下所示。 (除脚本标签外,与您的代码相同)
您可以运行以下代码
const { createElement} = React
const { render } = ReactDOM
const title = createElement(
'h1',
{id: 'title', className: 'header'},
'Hello World'
)
render(
title,
document.getElementById('react-container')
)
<!DOCTYPE html>
<html lang="en">
<head>
<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>
<meta charset="UTF-8">
<title>Hello World with React</title>
</head>
<body>
<div id = "react-container"></div>
<script src = "index.js"></script>
</body>
</html>