反应本机错误(无效的元素类型)

时间:2020-08-09 23:40:54

标签: javascript android ios reactjs react-native

在iOS设备上启动我的应用程序时,出现此错误:

错误:元素类型无效:预期为字符串(对于内置组件)或类/函数 (对于复合组件),但gor:未定义。您可能忘记了从 定义文件,或者您可能混淆了默认导入和命名导入。

检查“应用”的渲染方法。

This error is located at:
  in App (created by ExpoRoot)
  in RNCAppearanceProvider (at src/index.tsx:70)
  in AppearanceProvider (created by ExpoRoot)
  in ExpoRoot (at renderApplication.js:45)
  in RCTView (at AppContainer.js:109)
  in DevAppContainer (at AppContainer.js:124)
  in RCTView (at AppContainer.js:135)
  in AppContainer (at renderApplication.js:39)

这是我的App.js:

import * as React from "react";
import { View, Text, Button, Alert } from "react-native";
import {
  NavigationContainer,
  createDrawerNavigator,
} from "@react-navigation/drawer";

function HomeScreen({ navigation }) {
  return (
    <View style={{ flex: 1, alignItems: "center", justifyContent: "center" }}>
      <Text>Home Screen</Text>
      <Button
        title="Move to the Details Page"
        onPress={() => navigation.navigate("Details")}
      />
    </View>
  );
}

function DetailsScreen() {
  return (
    <View style={{ flex: 1, alignItems: "center", justifyContent: "center" }}>
      <Text>Details Screen</Text>
      <Button title="Go back to the Home" onPress={() => navigation.goBack()} />
    </View>
  );
}

// Drawer navigation:
const Drawer = createDrawerNavigator();

export default function App() {
  return (
    <NavigationContainer>
      <Drawer.Navigator initialRouteName="Home">
        <Drawer.Screen name="Home" component={HomeScreen} />
        <Drawer.Screen name="Details" component={DetailsScreen} />
      </Drawer.Navigator>
    </NavigationContainer>
  );
}

由于我没有使用类,因此声明“检查App的呈现方法”。我搜索了一下,发现作为React Native中的一个常见错误,可以通过调整进出口来解决,但不幸的是,它对我没有用。

感谢您的意见,对不起,仍然在学习:)

2 个答案:

答案 0 :(得分:1)

NavigationContainer 未从 @react-navigation/drawer 导出。See docs here !

import { NavigationContainer } from '@react-navigation/native';

答案 1 :(得分:0)

您不好导入NavigationContainer,为避免类型问题,我建议输入打字稿:)

df = df[(~df[['phase_1','phase_2','phase_3','phase_4']].isin(['MU#1','MU#2'])).all(1)]