首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >TypeError:尝试使用google-maps-react时,无法读取未定义的属性“”array“”

TypeError:尝试使用google-maps-react时,无法读取未定义的属性“”array“”
EN

Stack Overflow用户
提问于 2017-10-08 18:03:10
回答 1查看 1.1K关注 0票数 3

我是ReactJS新手,但对React Native很熟悉。我正在尝试获得一个基本的地图组件来显示。

我的地图组件是

WaterMapView.js

代码语言:javascript
复制
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中,如下所示:

代码语言:javascript
复制
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组件是:

代码语言:javascript
复制
import React from 'react';
import MainDashboard from './MainDashboard'; 

const App = () => {
        return (
            <div>
                <MainDashboard />
            </div>
        )
};

export default App

index.js是:

代码语言:javascript
复制
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语句‘我在这里’。

让我知道我错过了什么。

EN

回答 1

Stack Overflow用户

发布于 2017-10-08 19:04:12

代码语言:javascript
复制
<div style={mapDisplayStyle} >
                WaterMapView
</div>

应该是

代码语言:javascript
复制
<div style={mapDisplayStyle} >
  <WaterMapView />
</div>

否则,react只会将WaterMapView解释为字符串并显示该字符串。当您想要使用/呈现组件时,您需要将<>添加到id中。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46629867

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档