嗨,我开始使用 react native,但是我在将 nativebase 与 expo 一起使用时遇到了问题。 使用文档中的代码时会出现此错误: 元素类型无效:应为字符串(对于内置组件)或类/函数(对于复合组件)但得到:未定义。您可能忘记从定义组件的文件中导出组件,或者您可能混淆了默认导入和命名导入。 检查'App'的渲染方法 [这里是错误] (https://ibb.co/nQpBqYv)
import React from 'react';
import { AppLoading } from 'expo-app-loading';
import { Container, Text } from 'native-base';
import * as Font from 'expo-font';
import { Ionicons } from '@expo/vector-icons';
export default class App extends React.Component {
constructor(props) {
super(props);
this.state = {
isReady: false,
};
}
async componentDidMount() {
await Font.loadAsync({
Roboto: require('native-base/Fonts/Roboto.ttf'),
Roboto_medium: require('native-base/Fonts/Roboto_medium.ttf'),
...Ionicons.font,
});
this.setState({ isReady: true });
}
render() {
if (!this.state.isReady) {
return <AppLoading />;
}
return (
<Container>
<Text>Open up App.js to start working on your app!</Text>
</Container>
);
}
}
答案 0 :(得分:1)
问题不在于 nativebase。您实际上需要更正以下导入语句,
import { AppLoading } from 'expo-app-loading';
以下,
import AppLoading from 'expo-app-loading';