React.JS 中的组件元素无效

Invalid Component Element in React.JS

我一直在学习 react.js 教程,其中包含一个简单的 hello world 示例。我找不到以下内容不起作用的原因,但我一直收到此错误。

Uncaught Error: Invariant Violation: React.render(): Invalid component element.

我有以下代码。如果我这样做似乎可行 React.createElement,但不适用于 JSX 元素。

<!doctype html>
<html>
<head>
    <script src="https://fb.me/react-0.13.3.js"></script>
    <script src="https://fb.me/JSXTransformer-0.13.3.js"></script>
    <script type="text/jsx">
        document.body.onload = function(){
            console.log("shuff")
            var HelloWorld = React.createClass({
                render: function(){
                    return <div>Hello, Ian Shuff!</div>;
                }
            });

            React.render( new HelloWorld(), document.getElementById("test"))
        }

    </script>
</head>
<body>
    <div id="test"></div>
</body>
</html>

您应该传递给渲染 <HelloWorld />,而不是 new HelloWorld()

React.render(<HelloWorld />, document.getElementById("test"))

Example

jsx-in-depth

或者你可以使用React.createElement,像这样

React.render(React.createElement(HelloWorld, null), document.getElementById("test"))

Example