我从我的一个旧项目中复制了我的代码,所以它应该能够工作。然而,我认为当我创建新项目时,它意外地更新了版本,导致它彻底出错。这是我的代码:
import React, {useState} from 'react';
import { Text, View } from 'react-native';
import * as Font from 'expo-font';
import { AppLoading} from 'expo-app-loading';
import {enableScreens} from 'react-native-screens'
//import from libraries
import TabNavigation from './Navigation';
//import TabNavigation
enableScreens();
const fetchFonts = () => {
return Font.loadAsync({
'open-sans': require('./assets/fonts/OpenSans-Regular.ttf'),
'open-sans-bold' : require('./assets/fonts/OpenSans-Bold.ttf')
});
//fetch fonts from the folder so that we can style the title
};
export default function App() {
const[fontLoaded, setFontLoaded] = useState(false);
if(!fontLoaded){
return (
<AppLoading
startAsync ={fetchFonts}
onFinish={()=> setFontLoaded(true)}
/>
);
}
//this will ensure that the font will always be loaded.
return(
<TabNavigation />
);
}我尝试做的事情是运行这个程序,然后返回导航,所有导航过程都在那里工作。
以下是错误:组件异常元素类型无效:应为字符串(对于内置组件)或类/函数(对于完整组件),但got: undefined。您可能忘记了从中导出组件。定义它的文件,或者您可能混淆了默认的和命名的导入。检查“App”的render方法。
发布于 2021-01-18 20:13:13
您不需要执行此fetchFonts方法来加载字体。如果您正确安装了字体,您只需将属性fontFamily放入任何样式中,并使用字体名称作为其值,例如:textStyle:{ fontFamily: 'Montserrat-Bold' }为了更好地理解,您可以查看此link。
发布于 2021-06-27 11:00:50
将你的应用加载导入AppLoading从‘expo- app - Loading’改为;
发布于 2021-07-29 18:16:39
首先,打开终端,进入项目目录。
第二步,执行以下命令安装expo-app-loading模块:
expo-app-loading
第三,将模块导入到App.js文件中:
import AppLoading from 'expo-app-loading';
在Expo 4.9.0上测试
https://stackoverflow.com/questions/65774121
复制相似问题