我正在尝试使用react navigation导航到另一个屏幕。然而,通过这段代码,我得到了一个错误:
undefined is not an object (evaluation 'this.props.navigation')
navigate
直接(见底部示例)它可以工作。
我做错了什么?
这不起作用:
_renderRow (rowData) {
return (
<View >
<TouchableHighlight onPress={this._handlePress} underlayColor='white'>
<Image
style={{width: 50, height: 50}}
source={{uri: 'http://openweathermap.org/img/w/' + rowData.iconName + '.png'}}
/>
</TouchableHighlight>
</View>
)
}
_handlePress () {
this.props.navigation.navigate('Details')
}
这确实有效:
_renderRow (rowData) {
return (
<View >
<TouchableHighlight onPress={() => this.props.navigation.navigate('Details')} underlayColor='white'>
<Image
style={{width: 50, height: 50}}
source={{uri: 'http://openweathermap.org/img/w/' + rowData.iconName + '.png'}}
/>
</TouchableHighlight>
</View>
)
}