I am trying to print the state in console for debugging but getting error message
Cannot read property 'petname' of undefined
What is the right way to print state in console and why this is calling it a property?
export default class App extends Component<{}> {
constructor(props) {
super(props)
this.state = {
petname: '',
owner: ''
};
}
addPet() {
console.log("Button Pressed");
console.log(this.state.petname);
return (
//some logic
);
}
render() {
return (
<View style={styles.container}>
<View style={styles.inputStyle}>
<Text>Pet</Text>
<TextInput onChangeText={petname => this.setState({petname})} style={{width:100}} />
</View>
<View style={styles.inputStyle} >
<Button title="Add Pet" onPress={this.addPet} />
</View>
</View>
)
}
}