简体   繁体   English

使用Navigation.push(来自wix的本地导航v2)我没有在目标组件中获取道具。 我如何访问道具?

[英]With Navigation.push (v2 of react native navigation from wix) I am not getting props in destination component. How do I access props?

I am passing props using Navigation.push then trying to get the props as seen below in destination component. 我使用Navigation.push传递道具,然后尝试获取目标组件中的下面的道具。

Result of attempt: I get 'image of undefined' 尝试的结果:我得到'未定义的图像'

I am using redux in my react-native-app and redux is working correctly and I can see my data in other components. 我在react-native-app中使用redux,redux工作正常,我可以在其他组件中看到我的数据。 But when I do push and try to access the props in destination component I am seeing nothing. 但是当我按下并尝试访问目标组件中的道具时,我什么也看不到。

All I get is componentId and rootTag in placeDetail component when I just console.log the props. 当我只是console.log的道具时,我得到的就是在placeDetail组件中的componentId和rootTag。 What am I doing wrong? 我究竟做错了什么?

 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> ); }; 

Inside your Navigation.push everything should be inside the component object. 在Navigation.push里面,一切都应该在组件对象中。

like so: 像这样:

You currently have the options and pass props outside of the component. 您目前拥有选项并在组件外部传递道具。

 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM