Javascript 控制台抛出未终止的 JSX 内容错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33127130/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 14:40:14  来源:igfitidea点击:

Console is throwing Unterminated JSX contents error

javascriptreactjsbabeljs

提问by ajmajmajma

I am trying to set up a basic react example using jspm/systemjs and babel. I have this code here to show a simple page and am getting an error

我正在尝试使用 jspm/systemjs 和 babel 设置一个基本的反应示例。我在这里有这个代码来显示一个简单的页面,但出现错误

import React from 'react';

export default React.createClass({
displayName: 'MainComponent',
propTypes: {
    item: React.PropTypes.object
},
render: function render() {
    return (
        <div class="builder-conteiner">

        <div>;
    );
}
});

React.render(<MainComponent />, document.getElementById('app'))

Nothing is showing up, the console is throwing "Unterminated JSX contents", and babel is pointing to the react.renderline:

什么都没有显示,控制台正在抛出“未终止的 JSX 内容”,而 babel 指向该react.render行:

 17 | React.render(<MainComponent />, document.getElementById('app'))
    |                               ^ 

回答by JMM

You have 2 unclosed <div>tags in your render()and a semicolon that probably doesn't belong. I'd get rid of those (e.g. close them, delete the semicolon in <div>;if it doesn't belong) and try it again.

您有 2 个未闭合的<div>标签render()和一个可能不属于的分号。我会摆脱那些(例如关闭它们,<div>;如果它不属于,则删除分号)并再试一次。

回答by KARTHIKEYAN.A

Give / in closing div element and remove semicolon(;) after div element.

在关闭 div 元素中给出 / 并删除 div 元素后的分号(;)。

import React from 'react';

export default React.createClass({
displayName: 'MainComponent',
propTypes: {
    item: React.PropTypes.object
},
render: function render() {
    return (
        <div class="builder-conteiner">

        </div>
    );
}
});

React.render(<MainComponent />, document.getElementById('app'))