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?
use <HelloWorld/>
instead of new HelloWorld()
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With