使用 Navigation.push(来自 wix 的 react native navigation v2)我没有在目标组件中获取道具。我如何访问道具?
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 传递道具,然后尝试在目标组件中获取道具,如下所示。
尝试结果:我得到'image of undefined'
我在我的 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'
}
}
}
}
});
我正在使用 Navigation.push 传递道具,然后尝试在目标组件中获取道具,如下所示。
尝试结果:我得到'image of undefined'
我在我的 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'
}
}
}
}
});