我對 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?我沒有在任何地方訪問它。這可能看起來像這里問題的重復(fù), 但不同之處在于,在該問題中,解決方案涉及.bind(this)在提問者定義的函數(shù)上使用。我沒有這樣的功能,我可以調(diào)用它。任何幫助將不勝感激。
TypeError: undefined is not an object in
慕碼人2483693
2022-10-21 10:14:21