【发布时间】:2021-08-17 22:10:25
【问题描述】:
我正在制作一个反应原生应用程序,现在正试图放置一个下载的字体,我一直在检查应用程序错误的渲染方法,然后在它下面,它说这个
此错误位于: 在 App 中(由 ExpoRoot 创建) 在 ExpoRoot (在 renderApplication.js:45) 在 RCTView 中(在 View.js:34) 在视图中(在 AppContainer.js:106) 在 RCTView 中(在 View.js:34) 在视图中(在 AppContainer.js:132) 在 AppContainer 中(在 renderApplication.js:39 处)
我看过类似的问题,但他们的解决方案没有解决我的问题,所以我从他们的解决方案中得知这是导入或导出错误,但我的所有东西都正确导入和导出,所以我不知道是什么问题不再是了。这就是我当前的代码的样子
import React, {useState} from 'react';
import { View } from 'react-native';
import * as Font from 'expo-font';
import Home from './screens/Home';
import AppLoading from 'expo';
const getFonts = () =>
Font.loadAsync({
"Alef-Bold": require("./assets/fonts/Alef-Bold.ttf")
})
export default function App() {
const [fontsLoaded, setFontsLoaded] = useState(false);
if(fontsLoaded){
return (
<View>
<Home />
</View>
);
} else {
return (
<AppLoading startAsync={getFonts} onFinish={() => setFontsLoaded(true)} />
)
}
}
这是 Home 组件
import React from 'react'
import {StyleSheet, Text, View } from 'react-native'
function Home() {
return (
<View style={styles.container}>
<Text style={styles.titleText}>Welcome to the home page</Text>
</View>
)
}
const styles = StyleSheet.create({
container: {
padding: 50,
},
titleText: {
fontFamily: "Alef-Bold",
}
})
export default Home
请问我该如何解决呢?
【问题讨论】:
-
你能发布你得到的确切错误吗?
-
这是第一个错误错误:元素类型无效:期望字符串(对于内置组件)或类/函数(对于复合组件)但得到:未定义。您可能忘记从定义组件的文件中导出组件,或者您可能混淆了默认导入和命名导入。检查
App的渲染方法。我没有足够的字符来输出其余的错误,所以我更新了问题 -
你的
AppLoading导入有误,你要这样导入import AppLoading from 'expo-app-loading'; -
@KartikeyVaish 这个错误给了我这个错误 undefined Unable to resolve module expo-app-loading from C:\Users\lenovo\Desktop\projekten\gamezone\App.js: expo-app-loading can在项目中找不到。如果您确定该模块存在,请尝试以下步骤: 1. 清除 watchman 手表:watchman watch-del-all 2. 删除 node_modules 并运行 yarn install 3. 重置 Metro 的缓存:yarn start --reset-cache 4. 删除缓存: rm -rf /tmp/metro-* 3 |从'expo-font'导入*作为字体; 4 |从'./screens/Home'导入主页; > 5 |从'expo-app-loading'导入AppLoading
-
你必须像这样安装应用程序加载
expo install expo-app-loading看我的回答
标签: reactjs react-native function fonts expo