react-native
react-native copied to clipboard
ES6 and NavigatorIOS: message: Cannot read property 'navigator' of undefined
hi,I write the code like this,but report an error: message: Cannot read property 'navigator' of undefined and I try another way without ES6,everything ok. something wrong with ES6?
class MyView extends React.Component {
constructor(props) {
super(props);
this.state = {};
}
editMyData() {
this.props.navigator.push({
component: EditMyData,
title: 'editMyData'
})
}
render() {
return (
<ScrollView style={styles.container} showsVerticalScrollIndicator={false}>
<View style={styles.header}>
<View style={styles.user}>
<Image style={styles.myImage} source={require('image!logo')}/>
<Text>test</Text>
</View>
<TouchableHighlight onPress={this.editMyData}>
When you create components as ES6 classes methods are not bound to instance automatically. Try this:
class MyView extends React.Component {
constructor(props) {
super(props);
this.editMyData = this.editMyData.bind(this);
this.state = {};
}
...
it works,thanks