TypeError: Cannot read property 'array' of undefined when trying to use google-maps-react
See original GitHub issueI 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.
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (1 by maintainers)
Top Results From Across the Web
Cannot read property 'array' of undefined when trying to use ...
I am new to ReactJS, but familiar with React Native. I am trying to to get a basic map component to be displayed....
Read more >How to Prevent the TypeError: Cannot Read Property Map of ...
A guide on the root cause of 'cannot read map of undefined' as well as techniques and tools to prevent this error.
Read more >How to Read React Errors (fix 'Cannot read property of ...
This error usually means you're trying to use .map on an array, but that array ... TypeError: Cannot read property 'map' of undefined...
Read more >Fix the "Cannot read property 'map' of undefined" Error in React
In this post, we'll learn how to fix it. Why It's Happening. The variable you are trying to map over is undefined ....
Read more >cannot read properties of undefined (reading 'map') - You.com
To fix this error, initialize the value you are mapping over to an empty array or check that the data you are trying...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Pretty sure this is related to proptypes being deprecated in React 16: https://github.com/facebook/prop-types
I am using react-native-slideshow but I get this error: Cannot read property ‘arrayOf’ of undefined.
I did as some answer suggested: // install prop-types module // then import it in the codebase import React, { Component } from ‘react’; import PropTypes from ‘prop-types’; import Slideshow from ‘react-native-slideshow’;
export default class App extends Component {
render() { return ( <Slideshow dataSource={[ { url:‘http://placeimg.com/640/480/any’ }, { url:‘http://placeimg.com/640/480/any’ }, { url:‘http://placeimg.com/640/480/any’ } ]}/> ); } }
But I am still getting the same error: Help me please