简体   繁体   English

反应语法错误

[英]React syntax error

I'm following a tutorial to build a basic react app (first time using react) and am getting the following error when I try to run with nodemon: 我正在按照教程构建一个基本的反应应用程序(第一次使用react),当我尝试使用nodemon运行时出现以下错误:

SyntaxError: Unexpected token <

The offending < is in the main.js file 违规的<在main.js文件中

var React = require('react');
var App = require('./components/App');

React.render(
  <App />,
  document.getElementById('main')
);

As I say, I'm new to react - is there any way round the use of < here? 正如我所说,我是新手做出反应 - 是否有任何方式围绕使用<here? I've minified js as per the tutorial instructions. 我根据教程说明缩小了js。

Your React JSX code can live in a separate file. 您的React JSX代码可以存在于单独的文件中。 Lets name your file app.js 让我们为你的文件app.js命名

File content: 文件内容:

ReactDOM.render(
  <h1>Hello, world!</h1>,
  document.getElementById('example')
);

Then reference it from your HTML document: 然后从HTML文档中引用它:

<script type="text/babel" src="app.js"></script>

Click here to get more info 点击此处获取更多信息

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

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