Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I'm a react newbie

and I'm Creating a simple class and function and rendering to the body.

However,

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

<script src="https://fb.me/react-0.13.3.js"></script>
<script src="https://fb.me/JSXTransformer-0.13.3.js"></script>
<script src="https://code.jquery.com/jquery-2.1.3.min.js"></script>
<script type="text/jsx">

    var HelloWorld = React.createClass({
        render: function() {
            return <div>Hello, world!</div>;
        }
    });

    React.render(new HelloWorld(), document.body);

</script>


<body>

</body>
</html>

Any ideas on what is wrong?

like image 777
wolfgang Avatar asked Jun 02 '15 15:06

wolfgang


2 Answers

use <HelloWorld/> instead of new HelloWorld()

like image 162
wolfgang Avatar answered Nov 10 '22 06:11

wolfgang


Change React.render(new HelloWorld(), document.body); to React.render(React.createElement(HelloWorld), document.body); and it should work. The React.render function expects a ReactElement which you can create via React.createElement.

You can see the docs here along with some other useful functions: https://facebook.github.io/react/docs/top-level-api.html

like image 22
brettish Avatar answered Nov 10 '22 04:11

brettish