Javascript 在另一个屏幕导航V5-NATIVE中从屏幕获取参数
我试图从屏幕B中的屏幕A获取参数,但总是抛出错误,我就是这样做的:Javascript 在另一个屏幕导航V5-NATIVE中从屏幕获取参数,javascript,react-native,Javascript,React Native,我试图从屏幕B中的屏幕A获取参数,但总是抛出错误,我就是这样做的: go = (songs) => { this.props?.navigation.navigate("Artists_Song", {hola: "hola"}); } <TouchableOpacity onPress = {() => this.go(songs)}>
go = (songs) => {
this.props?.navigation.navigate("Artists_Song", {hola: "hola"});
}
<TouchableOpacity onPress = {() => this.go(songs)}>
<View style = {{
backgroundColor: "yellow",
width: Dimensions.get("window").width * 0.48,
marginBottom: 20,
marginLeft: 5,
alignItems: "center"}}
key = {artist}>
<Image source = {require("../assets/default_image.jpg")} style={{ width: Dimensions.get("window").width * 0.48, height: 100}}></Image>
<Text style = {{fontSize: 20, textAlign: "center"}}>
{
(artist.length > 15) ?
artist.substring(0,13).padEnd(15,".")
: artist
}
</Text>
</View>
</TouchableOpacity>
你能检查一下
this.props.navigation.state.params吗?
它告诉你:undefined不是一个评估this.props.navigation.state.params的对象。你正在使用的react导航的版本是什么?@jogesh_pi navigation v5
class Artists_Song extends React.Component {
render() {
return(
<>
<Artist_Song {...this.props}></Artist_Song>
</>
)
}
componentDidMount() {
const songs = this.props.route.params;
console.log(songs);
}
render() {
return (
<>
<Text>Hola</Text>
</>
)
}
this.props.route.params.hola
this.props.navigation.route.params