Xin chào tôi mới trong phản ứng tự nhiên, mã của tôi là:this.state là undefined trong sự kiện onPress trong phản ứng tự nhiên
import React, {
View,
Text,
TextInput,
Component
} from 'react-native';
import Style from './styles/signin';
import Button from '../common/button';
export default class SignIn extends Component {
constructor(props) {
super(props);
this.state = {
email: '',
password: ''
};
}
render(){
return(
<View style={Style.container}>
<Text style={Style.label}>Email</Text>
<TextInput
style={Style.input}
onChangeText={(text) => this.setState({email: text})}
value={this.state.email}
/>
<Text style={Style.label}>Password</Text>
<TextInput
style={Style.input}
onChangeText={(text) => this.setState({password: text})}
value={this.state.password}
secureTextEntry={true}
/>
<Button text={'Sign in'} onPress={this.onPress}/>
</View>
);
}
onPress(){
console.log(this.state.email);
}
}
Khi tôi điền vào mẫu dưới và nhấn dấu này trong, tôi có thông báo lỗi này: "Không thể đọc email thuộc tính 'của không xác định". Cảm ơn sự giúp đỡ của bạn!
thx! nó hoạt động! – ImPuLsE