Reactjs TypeError:navigation.getParam不是函数

Reactjs TypeError:navigation.getParam不是函数,reactjs,react-native,react-navigation,Reactjs,React Native,React Navigation,我正在使用堆栈5版本的react导航 App.js export default class App extends React.Component { render() { return ( <NavigationContainer> <Stack.Navigator> <Stack.Screen name="Home" component={Home} /> <Stack.Screen

我正在使用堆栈5版本的react导航

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>
     )
  }
}
     <TouchableHighlight onPress={() => { this.props.navigation.navigate('Movie', { title: item.title, img: item.img, id: item.imdbID }) }}>
      // code omitted               
      </TouchableHighlight>
   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');
}
Movie.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>
     )
  }
}
     <TouchableHighlight onPress={() => { this.props.navigation.navigate('Movie', { title: item.title, img: item.img, id: item.imdbID }) }}>
      // code omitted               
      </TouchableHighlight>
   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');
}

你能帮我解决这个问题吗? 我在等待你的答复


提前感谢

这是使用导航传递
道具时
react native
中的常见问题。您可以尝试这种方法,看看它是否有效

//Home.js

<TouchableHighlight onPress={() => { this.props.navigation.navigate({'Movie', { title: item.title, img: item.img, id: item.imdbID }}) }}>
更新:


这是一个你需要的解决方案小吃,我对你的代码做了一些修改,你的错误现在在这个小吃中被修复了。
您试图访问getParams函数,但导航对象中没有该函数
,因此我没有使用getParams函数获取参数,而是直接从这个.pros.navigation.route.params获取这些参数


同样的问题。请看我的截图,因为我更新了我的第一篇文章!我已经更新了答案。更新console.log后,您可以在@adnansalahuddin上查看它吗。没什么。我在navigation.getParam上出错。它说的不是功能。我认为
const{navigation}=this.props const title=navigation.getParam('title','N/A')有问题您是否能够修复该问题@AdnanSalahuddinNope。如果你觉得舒服的话,我会和你分享点心。你能在世博会上用这个问题做点心吗?如果是,请与我共享,我会修复它。@Waheedaktar注意:不要使用web。试试android或IOS Thanksher,它是解决您在这小吃中问题的方法,如果它有效,请将我的问题标记为已接受。
    //Movie.js
    componentDidMount(){
          const navObject = this.props.navigation.state.params 
          console.log(navObject )
    }
this.state = {
    do:{
      name: props.route.params.name,
      color: props.route.params.color
    }
};