So I just started learning React and here's the first state example that I am working on.
Here's the code :-
<div id="app"></div>
<script src="https://npmcdn.com/react@15.3.1/dist/react.js"></script>
<script src="https://npmcdn.com/react-dom@15.3.1/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>
Here's the error in console:
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)
What wrong am I doing here? I tried to find some solutions googling the error I received in console, but nothing helped me. Would be great to get some expert comment on this.