简体   繁体   English

React Native MapView:undefined不是对象

[英]React Native MapView: undefined is not an object

I am a beginner in React Native and I am trying to use the MapView component from the 'react-native-maps' module. 我是React Native的初学者,我正在尝试使用“ react-native-maps”模块中的MapView组件。

This is my code: 这是我的代码:

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)

I am getting this error: 我收到此错误:

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

Can Anyone Help me? 谁能帮我?

PropTypes used to be included in React, but is now a separate package. PropTypes曾经包含在React中,但现在是一个单独的包。

npm i prop-types

Changes from: 更改自:

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

to

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

Example usage: 用法示例:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM