React Native MapView:undefined不是对象

时间:2017-11-26 20:02:19

标签: javascript reactjs react-native undefined react-proptypes

我是React Native的初学者,我正在尝试使用' react-native-maps'中的MapView组件。模块。

这是我的代码:

import React, { Component } from 'react';
import {
  Platform,
  StyleSheet,
  Text,
  AppRegistry,
  View
} from 'react-native';
import MapView from 'react-native-maps';


export default class LocationDisplay extends Component<{}> {

  render() {
    return (
      <MapView/>
    );
  }
}

AppRegistry.registerComponent('LocationDisplay', () => LocationDisplay)

我收到此错误:

undefined is not an object (evaluating ‘_react.PropTypes.string’)

任何人都可以帮助我吗?

1 个答案:

答案 0 :(得分:0)

PropTypes曾经包含在React中,但现在是一个单独的包。

npm i prop-types

更改自:

import React, { PropTypes, Component } from 'react';

import React, { Component } from 'react';
import PropTypes from 'prop-types';

使用示例:

class Item extends Component {
    static propTypes = {
        data: PropTypes.object.isRequired
    };
}