3

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.

arc
  • 71
  • 8

1 Answers1

0
<div style={mapDisplayStyle} >
                WaterMapView
</div>

Should be

<div style={mapDisplayStyle} >
  <WaterMapView />
</div>

Otherwise react just interprets WaterMapView as a string and displays the string. When you want to use/render the component you need to add < > to id.

Daniel
  • 1,933
  • 12
  • 17
  • Yes. I had caught that one. But correcting it does not have any impact of the error. The error remains the same. – arc Oct 08 '17 at 11:14