元素类型无效,您可能忘记导出组件
Element type is invalid, you likely forgot to export your component
尝试在 iOS 模拟器上 运行 我的代码时出现以下错误。错误指出 "Element type is invalid: expected a string (for built-in components) but got: undefined. You likely forgot to export your component from the file it's defined in."
我在其他人的帖子中看到了同样的问题,他们需要将 "export default App" 添加到文件末尾或在 class 的声明中使用 "export default class" .
我正在学习的教程是 https://medium.com/@gurusundesh/getting-started-with-react-native-mapview-5e0bd73aa602。可能是文章太旧了,react-native从那以后就变了。
如有任何关于如何解决此问题的建议,我们将不胜感激。
谢谢
/**
* Sample React Native App
* https://github.com/facebook/react-native
* @flow
*/
import React, { Component } from 'react';
import {
Platform,
StyleSheet,
Text,
View
} from 'react-native';
import { MapView } from 'react-native-maps';
const instructions = Platform.select({
ios: 'Press Cmd+R to reload,\n' +
'Cmd+D or shake for dev menu',
android: 'Double tap R on your keyboard to reload,\n' +
'Shake or press menu button for dev menu',
});
class App extends Component {
render() {
return (
<View style={styles.container}>
<MapView style={styles.map}
initialRegion={{
latitude:10,
longitude:20,
latitudeDelta:30,
longitudeDelta:40
}}
/>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
instructions: {
textAlign: 'center',
color: '#333333',
marginBottom: 5,
},
map: {
position: 'absolute',
top: 0,
bottom: 0,
left: 0,
right: 0,
}
});
export default App;
将您的 MapView 导入更改为:
import MapView from 'react-native-maps';
尝试在 iOS 模拟器上 运行 我的代码时出现以下错误。错误指出 "Element type is invalid: expected a string (for built-in components) but got: undefined. You likely forgot to export your component from the file it's defined in."
我在其他人的帖子中看到了同样的问题,他们需要将 "export default App" 添加到文件末尾或在 class 的声明中使用 "export default class" .
我正在学习的教程是 https://medium.com/@gurusundesh/getting-started-with-react-native-mapview-5e0bd73aa602。可能是文章太旧了,react-native从那以后就变了。
如有任何关于如何解决此问题的建议,我们将不胜感激。
谢谢
/**
* Sample React Native App
* https://github.com/facebook/react-native
* @flow
*/
import React, { Component } from 'react';
import {
Platform,
StyleSheet,
Text,
View
} from 'react-native';
import { MapView } from 'react-native-maps';
const instructions = Platform.select({
ios: 'Press Cmd+R to reload,\n' +
'Cmd+D or shake for dev menu',
android: 'Double tap R on your keyboard to reload,\n' +
'Shake or press menu button for dev menu',
});
class App extends Component {
render() {
return (
<View style={styles.container}>
<MapView style={styles.map}
initialRegion={{
latitude:10,
longitude:20,
latitudeDelta:30,
longitudeDelta:40
}}
/>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
instructions: {
textAlign: 'center',
color: '#333333',
marginBottom: 5,
},
map: {
position: 'absolute',
top: 0,
bottom: 0,
left: 0,
right: 0,
}
});
export default App;
将您的 MapView 导入更改为:
import MapView from 'react-native-maps';