【问题标题】:Unable to read the properties of my react navigation object无法读取我的反应导航对象的属性
【发布时间】:2022-12-13 01:13:04
【问题描述】:

尝试导航时出现以下错误:

Uncaught TypeError: Cannot read properties of undefined (reading 'navigate')

这是我的主要组成部分:

const Stack = createStackNavigator<StackParamList>();

type StackParamList = {
    Home: undefined;
    NewTrip: undefined;
  };

export default function UserStack() {
    return (
        <NavigationContainer>
            <Stack.Navigator>
                <Stack.Screen name="Home" component={HomeScreen} />
                <Stack.Screen name="NewTrip" component={NewTripsScreen} />
            </Stack.Navigator>
        </NavigationContainer>
    );
}

这是我未能成功调用它的地方:

const TripsProfileScreen: FunctionComponent<TripsSectionProfileProps> = (
  props, navigation
) => {
 
  return (
    <Container>
 <IconButton
            onPress={() =>  navigation.navigate('NewTrip')}
          </IconButton>
 </Container>
)

}

我究竟做错了什么?谢谢。

【问题讨论】:

    标签: typescript react-native react-navigation


    【解决方案1】:

    props 是带有routenavigation 的对象。

    function Screen({ route, navigation }: Props) {
      // ...
    }
    
    const Screen: FunctionComponent<Props> = ({route, navigation}) => {
      // ...
    }
    

    【讨论】:

    • 使用功能组件会怎样?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-05-30
    • 2019-01-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-16
    • 2018-11-08
    相关资源
    最近更新 更多