javascript - react native MapView : undefined is not an object

标签 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’)

有人可以帮助我吗?

最佳答案

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
    };
}

关于javascript - react native MapView : undefined is not an object,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47500469/

相关文章:

javascript - <abbr> html 标签问号

reactjs - 如何在 React-JSS 中使用 '@global'

javascript - 如何对对象数组进行排序?

javascript - React - 在 chrome 中调试时,出现 'document not defined' 错误

javascript - 清除文本输入 onPress()

javascript - 动态创建 jquery-ui 可拖动句柄

javascript - 在另一个类被称为 jQuery 后删除类

reactjs - 如何为每个测试重置 fetch-mock?

android - 在 ReactNative "concat imposible to open"中使用 ffmpeg concat 获取此错误

javascript - 应用程序被杀死时不会触发 onNotification()