【发布时间】:2021-06-15 17:26:00
【问题描述】:
我正在使用带有堆栈 5 版本的反应导航。
App.js
export default class App extends React.Component {
render() {
return (
<NavigationContainer>
<Stack.Navigator>
<Stack.Screen name="Home" component={Home} />
<Stack.Screen name="Movie" component={Movie} />
</Stack.Navigator>
</NavigationContainer>
)
}
}
Home.js
<TouchableHighlight onPress={() => { this.props.navigation.navigate('Movie', { title: item.title, img: item.img, id: item.imdbID }) }}>
// code omitted
</TouchableHighlight>
我单击电影项目以查看电影详细信息,但收到错误消息并显示:
TypeError: navigation.getParam is not a function
Movie.js
componentDidMount() {
this.getMovieDetails(this.props.navigation.getParam('id', 'n/a'))
}
getMovieDetails = async (id) => {
const results = await fetchById(id)
this.setState({ info: results })
}
render() {
const { navigation } = this.props
const title = navigation.getParam('title', 'N/A');
const img = navigation.getParam('img', 'https://banner2.kisspng.com/20180216/kee/kisspng-photographic-film-reel-clip-art-movie-film-5a8677562304e0.0541516415187618141435.jpg');
}
您能帮我解决这个问题吗? 我正在等待您的回复。
提前致谢
【问题讨论】:
-
你能在世博会上用这个问题做点心吗?如果是,请与我分享,我会修复它。
-
@WaheedAkhtar snack.expo.io/@adnan.salah84/04697d 注意:不要使用网络。试试安卓或者IOS 谢谢
-
这是您在此小吃中遇到的问题的解决方案,如果可行,请将我的问题标记为已接受。 snack.expo.io/@waheed25/home_movie
标签: reactjs react-native react-navigation