[英]Nothing happens when I try and add react to my site, it doesn't look like the browser is detecting the file
I am trying to add react to my site but nothing is happening.我正在尝试向我的网站添加反应,但没有任何反应。 I can't see where I am going wrong.
我看不出哪里出错了。
The site is built using HTML and I am adding react to it该站点是使用 HTML 构建的,我正在添加对它的反应
Here is my code:这是我的代码:
<div id="goalsReact"></div>
<!-- Load React. -->
<!-- Note: when deploying, replace "development.js" with "production.min.js". -->
<script src="https://unpkg.com/react@16/umd/react.development.js" crossorigin></script>
<script src="https://unpkg.com/react-dom@16/umd/react-dom.development.js" crossorigin></script>
<script type="text/babel" src="js/goals.js"></script>
<script src="js/scripts.js"></script>
<script type="text/jsx">
ReactDOM.render(
<Goals />,
document.getElementById('goalsReact');
);
</script>
In order to use JSX in your HTML file, like you're doing, you would need to add babel to transpile your code into regular JavaScript: https://reactjs.org/docs/add-react-to-a-website.html#quickly-try-jsx为了在您的 HTML 文件中使用 JSX,就像您正在做的那样,您需要添加 babel 以将您的代码转换为常规 JavaScript: Z5E056C500A1C4B6A7110B50D807BADE-react-Z: html#quickly-try-jsx
Here's a demo: https://codesandbox.io/s/stack-overflow-jsx-in-html-p7nnk?file=/index.html这是一个演示: https://codesandbox.io/s/stack-overflow-jsx-in-html-p7nnk?file=/index.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.