元素类型无效:需要一个字符串(对于内置组件)或 class/function(对于复合组件)但得到:未定义
Element type is invalid: expected a string (for built-in components) or class/function (for composite components) but got: undefined
您好,我开始使用 React Native,但是我在将 nativebase 与 expo 一起使用时遇到问题。
使用文档中的代码时出现此错误:
元素类型无效:应为字符串(对于内置组件)或 class / 函数(对于复合组件)但得到:未定义。您可能忘记从定义它的文件中导出您的组件,或者您可能混淆了默认导入和命名导入。
检查 '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>
);
}
}
问题不在于 nativebase。您实际上需要更正以下导入语句,
import { AppLoading } from 'expo-app-loading';
以下,
import AppLoading from 'expo-app-loading';
您好,我开始使用 React Native,但是我在将 nativebase 与 expo 一起使用时遇到问题。 使用文档中的代码时出现此错误: 元素类型无效:应为字符串(对于内置组件)或 class / 函数(对于复合组件)但得到:未定义。您可能忘记从定义它的文件中导出您的组件,或者您可能混淆了默认导入和命名导入。 检查 '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>
);
}
}
问题不在于 nativebase。您实际上需要更正以下导入语句,
import { AppLoading } from 'expo-app-loading';
以下,
import AppLoading from 'expo-app-loading';