类型错误:使用 Onpress 导航后无法读取未定义的属性“导航”

当我在 const 函数中使用导航时,出现错误“TypeError:无法读取未定义的属性‘导航’”。是否由于未定义的道具。我仍然是 React Native 的初学者到中级水平。这是我的代码:

const Home = (props) => {
  if (props.authState === 'signedIn')
    return (
      <View>
        <TouchableOpacity
          style={styles.submitButton4}
          title="Create Profile"
          color="orange"
          fontSize="18"
          padding="20"
          height="hp('7%')"
          width="wp('17.5%')"
          onPress={() => {
            props.navigation.navigate('Profilee');
          }}></TouchableOpacity>
      </View>
    );
  else return <></>;
};

导航:

const Stack = createStackNavigator();

function App() {
  return (
    <NavigationContainer>
      <Stack.Navigator>
        <Stack.Screen
          name="Appis"
          component={Appis}
          options={{ headerShown: false }}
        />
        <Stack.Screen
          name="Home"
          component={Home}
          options={{ headerShown: false }}
        />
        <Stack.Screen
          name="Profilee"
          component={Profile}
          options={{ headerShown: false }}
        />
      </Stack.Navigator>
    </NavigationContainer>
  );
}

export default App;

fairhu 回答:类型错误:使用 Onpress 导航后无法读取未定义的属性“导航”

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/11625.html

大家都在问