我是 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/