我是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';
to
import React, { Component } from 'react';
import PropTypes from 'prop-types';
示例用法:
class Item extends Component {
static propTypes = {
data: PropTypes.object.isRequired
};
}