私は 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>
ベストアンサー1
render に渡す必要が<HelloWorld />
あります。new HelloWorld()
React.render(<HelloWorld />, document.getElementById("test"))
React.createElement
または、次のように使用することもできます。
React.render(React.createElement(HelloWorld, null), document.getElementById("test"))