I'm new to React and Javascript and I'm trying to render the following React component:
'use strict';
var React = require('react');
import ToReadList from './toreadlist.js';
var ToRead = React.createClass({
getInitialState: function() {
return { bookTitles: [] };
},
handleSubmit: function(e) {
e.preventDefault();
this.state.bookTitles.push(React.findDOMNode(this.refs.bookTitleInput).value.trim());
this.setState({items: this.state.bookTitles});
},
render: function() {
return (<div>
<form onSubmit={this.handleSubmit}><input type="text" ref="bookTitleInput"></input>
<input type="submit"></input></form>
<ToReadList bookTitles={this.state.bookTitles} />
</div>
);
}
});
module.exports = ToRead;
But I am having the following error on my console: "Uncaught TypeError: Cannot read property 'toUpperCase' of undefined"
I tried to debug (because the error is obscure to me and no line in my code is indicated) and noticed that this particular line:
this.state.bookTitles.push()
causes the error.
Please help!
Edit The error is caused by a webpack var injection function:
function autoGenerateWrapperClass(type) {
return ReactClass.createClass({
tagName: type.toUpperCase(),
render: function() {
return new ReactElement(
type,
null,
null,
null,
null,
this.props
);
}
});
}
findDOMNode()
uses the toUpperCase()
function which actually is called on a null.
Example
var x = null
x.toUpperCase()// results in this error.
If you could post the findDOMNode()
code, we could trace out the error.
OR
Make sure that the toUpperCase()
is called on a non-null object
.
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