我正在尝试从ReactNative中的一个组件导航到另一个屏幕。但要关注
可能的未处理的承诺拒绝,TypeError:未定义不是对象(正在评估“ navigation.navigate”)]
以下是我的代码,我在其中等待获取位置的详细信息,然后想导航到包含这些详细信息的另一个屏幕。
constructor(props) {
super(props)
this.state = {status: 'initial'}
this._handlePress = this._handlePress.bind(this);
}
_handlePress = async ({navigation}) => {
const res = await this.props.fetchDetails(this.props.place_id)
console.log('result', res.geometry.location.lat)
navigation.navigate("Home", {selectedLocation: res.geometry.location});
}
我也尝试过this.props.navigation.navigate()
,但无法解决。
我得到关注:
[[未处理的承诺拒绝:TypeError:未定义不是对象(正在评估'_this.props.navigation.navigate']]] >>
以下为完整的组件代码:Pastebin Link
我正在尝试从ReactNative中的一个组件导航到另一个屏幕。但是要遵循可能的未处理的承诺拒绝,TypeError:undefined不是对象(正在评估'...
使用withNavigation
方法,因为您已经从react-navigation导入了它。