我对 Javascript 和 ReactJS 真的很陌生,并且对错误感到困惑TypeError: undefined is not an object (evaluating '_this.state = { destination: '' }')
这是我的代码:
import React, {Component} from 'react';
import { StyleSheet, View, TextInput } from 'react-native';
export default class SearchBar extends Component {
constructor() {
/*
this.state = {
destination: ''
};
*/
super();
}
render() {
return (
<View style={styles.inputContainer}>
<TextInput
style={styles.input}
/>
</View>
);
}
}
这段代码工作正常。但是一旦我取消评论
this.state = {
destination: ''
};
我得到了错误。为什么它在困扰我undefined?我没有在任何地方访问它。
这可能看起来像这里问题的重复, 但不同之处在于,在该问题中,解决方案涉及.bind(this)在提问者定义的函数上使用。我没有这样的功能,我可以调用它。
任何帮助将不胜感激。
慕的地10843
相关分类