所以我剛開始學習React,這是我正在開發的第一個狀態示例。React無狀態示例
下面的代碼: -
<div id="app"></div>
<script src="https://npmcdn.com/[email protected]/dist/react.js"></script>
<script src="https://npmcdn.com/[email protected]/dist/react-dom.js"></script>
<script>
//main render
ReactDOM.render(
React.createElement(TextAreaCounter, {text: 'Bob'}),
document.getElementById("app")
);
//create component now
var TextAreaCounter = React.createClass({
propTypes: {
text: React.propTypes.string,
},
getDefaultProps: function() {
return {
text: '',
};
},
render: function(){
return React.DOM.div(null,
React.DOM.textarea({
defaultValue: this.props.text,
}),
React.DOM.h3(null, this.props.text.length)
);
}
});
</script>
下面是控制檯的錯誤:
react.js:20150 Uncaught Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined.
at invariant (react.js:20150)
at ReactCompositeComponentWrapper.instantiateReactComponent [as _instantiateReactComponent] (react.js:18327)
at ReactCompositeComponentWrapper.performInitialMount (react.js:6256)
at ReactCompositeComponentWrapper.mountComponent (react.js:6139)
at Object.mountComponent (react.js:13787)
at mountComponentIntoNode (react.js:11873)
at ReactReconcileTransaction.perform (react.js:16987)
at batchedMountComponentIntoNode (react.js:11895)
at ReactDefaultBatchingStrategyTransaction.perform (react.js:16987)
at Object.batchedUpdates (react.js:10324)
什麼錯我在這裏幹什麼?我試圖找到一些解決方案,搜索我在控制檯中收到的錯誤,但沒有任何幫助。會很高興得到一些專家對此的評論。