簡體   English   中英

在異步函數中導航 - React Navigation - React Native

[英]Navigating in Async function - React Navigation - React Native

我試圖在 ReactNative 中從一個組件導航到另一個屏幕。 但是越來越關注

可能未處理的承諾拒絕,類型錯誤:未定義不是對象(評估“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: undefined is not an object (evaluating '_this.props.navigation.navigate')]

以下是完整的組件代碼: Pastebin Link

使用withNavigation方法,因為您已經從 react-navigation 導入了它。

export default withNavigation(LocationItem);

如果未解決,則將導航作為道具從使用過的地方傳遞。

<LocationItem navigation={this.props.navigation}/>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM