I see a number of questions on here relating to this same issue, but it seems none match the issue I’m having, and are a bit more complex.
I am in the process of learning ReactJS and React Native. I’m in the midst of reading and following the code examples from “Learning React Native” book here: https://github.com/bonniee/learning-react-native
For some reason, calling this.setState in the code below when the handleTextChange function is called, causes the “this.SetState is not a function.” error. My question is why? Unlike other questions about this same issue, I don’t believe my call to this.stateState is buried in a callback function or if statement. Why is it undefined?
Here is my code:
class WeatherProject extends Component { constructor(props) { super(props); this.state = { zip: "", forecast: null }; } _handleTextChange(event) { this.setState({zip: event.nativeEvent.text}); } render() { return ( <View style={styles.container}> <Text style={styles.welcome}> You input {this.state.zip}. </Text> <TextInput style={styles.input} onSubmitEditing={this._handleTextChange}/> </View> ); } }