如果像 <br> 这样的自关闭标签没有关闭,JSX 中是否有一个 API 可以忽略?

Is there an API in JSX to ignore if self closing tags like <br> is not closed?

我正在使用 JSX 创建一个简单的 ReactJS 组件,如下所示。

<script type="text/jsx">
        var HelloWorld = React.createClass({
            render: function() {
                return (

                    <div class="ui left icon input">
                        <input placeholder="Search users..." type="text" />
                          <i class="users icon"></i>
                    </div>

                    );
            }
        });
        React.render(<HelloWorld />, document.body);
    </script>

如果我关闭输入标签<input placeholder="Search users..." type="text" />,上面的代码可以正常工作。 如果我不关闭标签 <input placeholder="Search users..." type="text"> ,JSX 会抛出此错误并且不会呈现 React/JSX 组件:

我有一些遗留代码,其中 <input ><br> 等标签未关闭。根据 W3C,关闭这些标签也不是强制性的。 我想使用 JSX 将此代码移动到 React 组件。但是,如果 self closing/void 标签未关闭,我希望 JSX 忽略。

Is there an api or way to configure JSX to igonre this?

您必须关闭所有 JSX 标签。 JSX 被编译成函数调用,而不是编译成 HTML。如果有帮助,你可以把它想得更像 XHTML。