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

时间:2021-07-30 07:21:14

标签: javascript react-native expo react-navigation

当我在 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;

0 个答案:

没有答案