[英]Invalid Component Element in React.JS
我一直在通過一個簡單的hello world示例來閱讀react.js教程。 我找不到以下不應該工作的原因,但我不斷收到此錯誤。
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"))
或者您可以使用React.createElement
,就像這樣
React.render(React.createElement(HelloWorld, null), document.getElementById("test"))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.