react-native error - 检查 `App` 的渲染方法
react-native error - Check the render method of `App`
我是 运行 我的 react-native expo 通过 expo start
命令管理的项目,我不知道我的代码有什么问题导致我收到这个错误 -
Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.
Check the render method of `App`.
This error is located at:
in App (created by ExpoRoot)
in ExpoRoot (at renderApplication.js:45)
in RCTView (at View.js:34)
in View (at AppContainer.js:106)
in RCTView (at View.js:34)
in View (at AppContainer.js:132)
in AppContainer (at renderApplication.js:39)
这是我的代码 -
export default function App() {
let [fontsLoaded] = useFonts({
'PoetsenOne-Regular': require('./assets/fonts/PoetsenOne-Regular.ttf'),
});
if (!fontsLoaded) {
return <AppLoading />;
} else{
return (
<View style={styles.container}>
<Text style={styles.container}>Open up App.js to start working on your app!</Text>
<StatusBar style="auto" />
</View>
);
}
}
这是我的样式表 -
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
fontFamily: "PoetsenOne-Regular"
},
});
所以,我自己解决了这个问题,问题是 if-else 语句 -
if (!fontsLoaded) {
return <AppLoading />;
}
当我删除它时,错误本身解决了,return <AppLoading />;
是错误的主要原因,因为它没有正确导入,我导入了 import { AppLoading } from 'expo'
而不是 import AppLoading from 'expo-app-loading'
我是 运行 我的 react-native expo 通过 expo start
命令管理的项目,我不知道我的代码有什么问题导致我收到这个错误 -
Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.
Check the render method of `App`.
This error is located at:
in App (created by ExpoRoot)
in ExpoRoot (at renderApplication.js:45)
in RCTView (at View.js:34)
in View (at AppContainer.js:106)
in RCTView (at View.js:34)
in View (at AppContainer.js:132)
in AppContainer (at renderApplication.js:39)
这是我的代码 -
export default function App() {
let [fontsLoaded] = useFonts({
'PoetsenOne-Regular': require('./assets/fonts/PoetsenOne-Regular.ttf'),
});
if (!fontsLoaded) {
return <AppLoading />;
} else{
return (
<View style={styles.container}>
<Text style={styles.container}>Open up App.js to start working on your app!</Text>
<StatusBar style="auto" />
</View>
);
}
}
这是我的样式表 -
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
fontFamily: "PoetsenOne-Regular"
},
});
所以,我自己解决了这个问题,问题是 if-else 语句 -
if (!fontsLoaded) {
return <AppLoading />;
}
当我删除它时,错误本身解决了,return <AppLoading />;
是错误的主要原因,因为它没有正确导入,我导入了 import { AppLoading } from 'expo'
而不是 import AppLoading from 'expo-app-loading'