Tôi có đoạn mã sau:Phản ứng this.prop truy cập Native từ bên trong chức năng
module.exports = class Menu extends Component {
about() {
this.props.nav.push({
component: TestView,
title: 'Test View',
});
}
render() {
return (
<ScrollView
scrollsToTop={false}
style={styles.menu}
navigator={this.props.nav}>
<View style={styles.logoContainer}>
<Image
style={styles.logo}
source={{ uri, }}/>
</View>
<Text onPress={this.about} style={styles.item}>About</Text>
<Text style={styles.item}>Account</Text>
</ScrollView>
);
}
};
tôi tiếp tục nhận được thông báo lỗi:
"undefined is not an object ("evaluating this.props.nav")
khi "onPress" gọi là "this.about". Tôi đặt một console.log trong hàm render và tôi có thể thấy rằng this.props.nav chứa một giá trị. Vấn đề xảy ra trong hàm about() và tôi không chắc chắn tại sao.
Mọi đề xuất sẽ tuyệt vời?
Cảm ơn