Skip to content

TypeError: Cannot read property 'array' of undefined when trying to use google-maps-react #129

@abhaychitnis

Description

@abhaychitnis

I am new to ReactJS, but familiar with React Native. I am trying to to get a basic map component to be displayed.

My map component is

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)

This component is embedded in MainDashboard.js as follows :

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>
    );
  };
};

My App.js component is :

import React from 'react';
import MainDashboard from './MainDashboard'; 

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

export default App

And index.js is :

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();

I am using React version 16.0.0 and google-maps-react version 1.1.0

I get an error accompanied by a dump of code. The error is :

TypeError: Cannot read property 'array' of undefined

I am not including the dump in this post. I can add that if required.

The problem seems very basic as the I do not even see the console.log statement 'I am here' in WaterMapView.js component.

Let me know what am I missing.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions