【问题标题】:React Native Error (Invalid Element Type)React Native 错误(无效的元素类型)
【发布时间】:2020-08-09 23:40:54
【问题描述】:

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

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

检查'App'的渲染方法。

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 中的一个常见错误,可以通过调整导入和导出来解决,但不幸的是它对我没有用。

【问题讨论】:

    标签: javascript android ios reactjs react-native


    【解决方案1】:

    你不好导入 NavigationContainer,为了避免类型问题我推荐 typescript :)

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

    【讨论】:

      【解决方案2】:

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

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

      【讨论】:

        猜你喜欢
        • 2021-01-08
        • 1970-01-01
        • 1970-01-01
        • 2017-07-11
        • 2018-02-07
        • 1970-01-01
        • 2020-07-02
        • 1970-01-01
        • 2018-05-18
        相关资源
        最近更新 更多