我有 MapContainer:
import React, { Component } from "react";
import ReactDOM from "react-dom";
export class MapContainer extends Component {
componentDidUpdate(props) {
this.loadMap();
}
loadMap() {
if (this.props && this.props.google) {
const {google} = this.props;
const maps = google.maps;
const mapRef = this.refs.map;
const node = ReactDOM.findDOMNode(mapRef);
const mapConfig = Object.assign({}, {
center: {lat: 50.4418782, lng: 30.5107196},
zoom: 15,
})
this.map = new maps.Map(node, mapConfig);
addMarker({lat: 50.4418782,lng: 30.5107196});
function addMarker(coords) {
const marker = new google.maps.Marker({
position: coords,
map: this.map
});
}
}
}
render() {
const style = {
width: '100%',
height: '40rem',
margin: '2rem auto'
};
return (
<div ref="map" style={style}>
loading map...
</div>
)
}
}
export default MapContainer;
当它开始我有TypeError:
无法读取未定义的属性“地图”。在此处输入图像描述
怎么了?