我是ReactJS新手,但对React Native很熟悉。我正在尝试获得一个基本的地图组件来显示。
我的地图组件是
WaterMapView.js
import React, { Component } from 'react';
import { Map, InfoWindow, Marker, GoogleApiWrapper } from 'google-maps-react';
export class WaterMapView extends Component {
render () {
console.log(' I am here ');
return (
<Map
google={this.props.google}
style={styles.mapStyle}
initialCenter={{
lat: 40.854885,
lng: -88.081807
}}
zoom={15}
/>
)
}
}
const styles = {
mapStyle: {
height: '100%',
width: '100%'
}
}
export default GoogleApiWrapper({
apiKey: 'AIxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
})(WaterMapView)此组件嵌入在MainDashboard.js中,如下所示:
import React, { Component } from 'react';
import windowSize from 'react-window-size';
import WaterMapView from './WaterMapView';
class MainDashboard extends Component {
render () {
const height = this.props.windowHeight;
const {
containerStyle,
headerStyle,
navigationStyle,
mainPageStyle,
eventPageStyle,
mapPageStyle,
mapDisplayStyle,
mapPropertiesStyle
} = styles;
return (
<div style={{ ...containerStyle, height }} >
<div style={headerStyle} >
</div>
<div style={navigationStyle} >
</div>
<div style={mainPageStyle} >
<div style={eventPageStyle} >
</div>
<div style={mapPageStyle} >
<div style={mapDisplayStyle} >
<WaterMapView />
</div>
<div style={mapPropertiesStyle} >
</div>
</div>
</div>
</div>
);
};
};我的App.js组件是:
import React from 'react';
import MainDashboard from './MainDashboard';
const App = () => {
return (
<div>
<MainDashboard />
</div>
)
};
export default Appindex.js是:
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './Components/App';
import registerServiceWorker from './registerServiceWorker';
ReactDOM.render(<App />, document.getElementById('root'));
registerServiceWorker();我使用的是React版本16.0.0和google-maps-react版本1.1.0
我得到一个错误,并伴随着一堆代码。错误是:
数组:无法读取未定义的TypeError的属性“array”
我不会在这篇文章中包括转储。如果需要,我可以添加这一点。
这个问题看起来很基本,因为在WaterMapView.js组件中我甚至看不到console.log语句‘我在这里’。
让我知道我错过了什么。
发布于 2017-10-08 19:04:12
<div style={mapDisplayStyle} >
WaterMapView
</div>应该是
<div style={mapDisplayStyle} >
<WaterMapView />
</div>否则,react只会将WaterMapView解释为字符串并显示该字符串。当您想要使用/呈现组件时,您需要将<>添加到id中。
https://stackoverflow.com/questions/46629867
复制相似问题