【问题标题】:React.createElement: type is invalid (map)React.createElement:类型无效(地图)
【发布时间】:2020-04-25 14:17:01
【问题描述】:

我是新来的反应并尝试创建在应用程序上显示的地图元素。但是,当我说我正在导出默认类 App 时,我相信我做错了。这是我得到的错误“React.createElement: type is invalid -- 期望一个字符串(用于内置组件)或一个类/函数(用于复合组件)但得到:“未定义””我的代码如下。

   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: 37.78825,
              longitude: -122.4324,
              latitudeDelta: 0.922,
              longitudeDelta: 0.0421,
           }
         }
       }  
   render() {  
       return (
         <View style={styles.container}>
          <Text>Home Sreen</Text>
          <MapView
            initialRegion={this.state.region}
            showsCompass={true}
            rotateEnabled={false}
            style={{flex: 1}}
         />
       </View>
      );
    }
   }
   const styles = StyleSheet.create({
      container: {
      flex: 1,
      backgroundColor: '#fff',
   },
   });

【问题讨论】:

标签: javascript reactjs react-native


【解决方案1】:

尝试从类中删除导出默认值并将其添加到程序的最后一行

Export default appname;

【讨论】:

  • 这没什么区别(大写E也不应该在那里)
  • 大声笑..这是错字..我知道
【解决方案2】:

代替

import { MapView } from 'expo';

使用

import MapView from 'react-native-maps';

【讨论】:

  • @GMccread 如果这个答案已经解决了你的问题,请考虑接受它。
猜你喜欢
  • 2017-12-22
  • 2018-07-22
  • 2019-08-19
  • 2021-02-24
  • 1970-01-01
  • 1970-01-01
  • 2018-12-25
  • 2017-07-17
  • 2019-11-03
相关资源
最近更新 更多