简体   繁体   English

渲染功能语法中的ReactJS错误

[英]ReactJS error in syntax at render function

I wrote a react class but Chrome is throwing a syntax error in the render function. 我编写了一个react类,但是Chrome在render函数中引发了语法错误。

I'm attaching the code here: 我在这里附加代码:

 var Chatrooms = React.createClass({ getInitialState: function() { return { loaded: false, pages: undefined, id: "-1", }; }, loadPages: function() { url = "/chat/api/chatroom/" + this.props.course + "/get/?format=json"; request = ajax_json_request(url, "GET", {}); request.done(function(response) { response = jQuery.parseJSON(response); oldState = this.state; oldState['chatrooms']=response; oldState['loaded']=true; this.setState(oldState); }.bind(this)); }, componentDidMount: function() { if(!this.state.loaded) { this.loadPages(); } }, render: function(){ console.log(this.state.chatrooms); return ( <div></div> ); } }); 

Browser is showing the error in line <div></div> as Uncaught SyntaxError: Unexpected token < . 浏览器在<div></div>行中将错误显示为Uncaught SyntaxError: Unexpected token < I checked the syntax online and it looks good to me. 我在线检查了语法,对我来说看起来不错。

您必须使用<script type="text/javascript">而不是<script type="text/jsx">

Try adding the JSX pragma on the top of the JSX file: 尝试在JSX文件顶部添加JSX编译指示:

/** @jsx React.DOM */

This is tells the browser to use the JSX directive. 这告诉浏览器使用JSX指令。

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

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