TypeError : props.navigation.getParam 不是函数。In(props.navigation.getParam('name')

Rau*_*ngh 13 react-native react-navigation

我面临的问题TypeError : props.navigation.getParam不是函数。在(props.navigation.getParam('name'). 我正在使用reactNavigation version 5.x.此代码在reactNavigation 3. 我究竟做错了什么?

这是我的代码

export default class ChatScreen extends Component {
static navigationOption = ({ navigation }) => {
    return {
        title: navigation.getParam('name', null)
    }
}
 
constructor(props) {
    super(props);
   
  
    this.state = {
        person:{
           name:props.navigation.getParam('name'),
            phone:props.navigation.getParam('phone'),
            // name:'Raushan',
          //   phone:9931428888
        },
        textMessage: ''
    };
   
}
Run Code Online (Sandbox Code Playgroud)

状态部分值错误。堆栈导航器

`

const Stack = createStackNavigator();
function App() {
  return (
    <NavigationContainer>
      <Stack.Navigator initialRouteName="Auth">
        <Stack.Screen name="AuthLoading" component={AuthLoadingScreen} />
        <Stack.Screen name="App" component={HomeScreen} options={{ title: 'Chats' }}/>
        <Stack.Screen name="Chat" component={ChatScreen} options={({ route }) => ({ title: route.params.name })}/>
        <Stack.Screen name="Auth" component={LoginScreen} />
      </Stack.Navigator>
    </NavigationContainer>
  );
}
export default App;
Run Code Online (Sandbox Code Playgroud)

`

和导航屏幕

onPress={()=>this.props.navigation.navigate('Chat',item)}

Rau*_*ngh 47

使用 props.route.params.name这是有效的

 this.state = {
    person:{
      name: props.route.params.name,
      phone: props.route.params.phone,
    },
    textMessage: ''
};
Run Code Online (Sandbox Code Playgroud)

  • 这有效。此外,到处都在使用 navigation.getParams 但它不再有效,这很疯狂 (3认同)
  • @Swift,这可能是因为新版本的导航库 (2认同)