![](/img/trans.png)
[英]How do I save state when getting values from navigation props? React-native
[英]With Navigation.push (v2 of react native navigation from wix) I am not getting props in destination component. How do I access props?
我使用Navigation.push傳遞道具,然后嘗試獲取目標組件中的下面的道具。
嘗試的結果:我得到'未定義的圖像'
我在react-native-app中使用redux,redux工作正常,我可以在其他組件中看到我的數據。 但是當我按下並嘗試訪問目標組件中的道具時,我什么也看不到。
當我只是console.log的道具時,我得到的就是在placeDetail組件中的componentId和rootTag。 我究竟做錯了什么?
Navigation.push(this.props.componentId, { component: { name: "navigation.playground.PlaceDetailScreen" }, options: { topBar: { title: { text: selPlace.name } } }, passProps: { selectedPlace: selPlace } });
const placeDetail = props => { console.log(props) return ( <View style={styles.container}> <View> <Image source={props.navigationselectedPlace.image} style={styles.placeImage} /> <Text style={styles.placeName}>{props.selectedPlace.name}</Text> </View> <View> <TouchableOpacity onPress={props.onItemDeleted}> <View style={styles.deleteButton}> <Icon size={30} name="ios-trash" color="red" /> </View> </TouchableOpacity> </View> </View> ); };
在Navigation.push里面,一切都應該在組件對象中。
像這樣:
您目前擁有選項並在組件外部傳遞道具。
Navigation.push(this.props.componentId, { component: { name: 'example.PushedScreen', passProps: { text: 'Pushed screen' }, options: { topBar: { title: { text: 'Pushed screen title' } } } } });
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.