React Native - 警告:React.createElement:类型无效——需要一个字符串(对于内置组件)或一个 class/function

React Native - Warning: React.createElement: type is invalid -- expected a string (for built-in components) or a class/function

我正在学习 React Native 并且我正在导入 AppLoading 以使用自定义字体我遇到了这个错误:

警告:React.createElement:类型无效 -- 应为字符串(对于内置组件)或 class/function(对于复合组件)但得到:未定义。您可能忘记从定义它的文件中导出您的组件,或者您可能混淆了默认导入和命名导入。

我的app.js

import React, { useState } from 'react';
import * as Font from 'expo-font';
import Home from './screens/Home';
import { AppLoading } from 'expo-app-loading';

const getFonts = () =>
  Font.loadAsync({
    'nunito-regular': require('./assets/Fonts/Nunito-Regular.ttf'),
    'nunito-bold': require('./assets/Fonts/Nunito-Bold.ttf'),
  });

export default function App() {
  const [fontsLoaded, setFontsLoaded] = useState(false);

  if (fontsLoaded) {
    return <Home />;
  } else {
    return <AppLoading startAsync={getFonts} onFinish={() => setFontsLoaded} />;
  }
}

我的Home.js

import React from 'react';
import { StyleSheet, View, Text } from 'react-native';

export default function Home() {
  return (
    <View style={styles.container}>
      <Text style={styles.titleText}>Home Screen</Text>
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    padding: 24,
  },

  titleText: {
    fontFamily: 'nunito-bold',
    fontSize: 18,
  },
});

or you might have mixed up default and named imports.

这就是问题所在。

你导入这个:

import { AppLoading } from "expo-app-loading";

The docs say 导入:

import AppLoading from 'expo-app-loading';