【发布时间】:2020-02-19 20:20:47
【问题描述】:
我一直在关注一个关于尝试通过使用 react native 和 expo 在移动应用程序上实现地图的教程,但是在运行代码后,我不断收到多个错误消息,而提供教程的 youtuber 没有体验到这些错误消息。
疑似问题
错误似乎是因为我试图从“expo”导入,但我不认为 expo 组件导出地图视图?
尝试的解决方案
npm install expo --save
面临的错误
Invariant Violation:元素类型无效:应为字符串(对于内置组件)或类/函数(对于复合组件),但得到:未定义。您可能忘记从定义组件的文件中导出组件,或者您可能混淆了默认导入和命名导入。
查看App的渲染方法。
import React from 'react';
import { StyleSheet, Text, View } from 'react-native';
import { MapView } from 'expo';
export default class App extends React.Component {
constructor(props) {
super(props);
this.state =
{
region :
{
latitude: 1.290270,
longitude: 103.851959,
latitudeDelta: 0.02,
longitudeDelta: 0.02,
}
}
}
render()
{
return (
<View style={styles.container}>
<Text>HomeScreen!</Text>
<MapView
initialRegion = {this.state.region}
showsUserLocation = {true}
showsCompass = {true}
rotateEnabled = {false}
style = {{flex:1}}
/>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
},
});
【问题讨论】:
标签: javascript react-native expo