Uncaught TypeError: Cannot read property 'overlayMouseTarget' of null
See original GitHub issueI previously posted this on StackOverflow but since this is less of a “how to” question and more a case of “there might be a bug with the Overlay component”, I decided to repost it here.
When leaving the page that has the map with some OverlayView’s, I get the error message:
Uncaught TypeError: Cannot read property ‘overlayMouseTarget’ of null
Here is the code with the GoogleMap component:
const GMap = withGoogleMap((props) => (
<GoogleMap
ref={props.onMapMounted}
defaultZoom={12}
zoom={props.zoom}
onDragEnd={props.onZoomChanged}
onZoomChanged={props.onZoomChanged}
defaultCenter={props.defaultCenter}
center={props.center}
>
{
props.markers && props.markers.map((data, index) => (
<OverlayView
key={index}
position={{
lat: data.get('loc').get('geo').get('lat'),
lng: data.get('loc').get('geo').get('lng'),
}}
mapPaneName={OverlayView.OVERLAY_MOUSE_TARGET}
getPixelPositionOffset={(width, height) => ({ x: -(width / 2), y: -(height) })}
>
<WnmMarker
text={data.get('text')}
highlight={data.get('highlight')}
/>
</OverlayView>
))
}
</GoogleMap>
));
Could it be that something is missing in the componentWillUnmount?
Issue Analytics
- State:
- Created 6 years ago
- Reactions:6
- Comments:24 (6 by maintainers)
Top Results From Across the Web
react-google-maps Uncaught TypeError: Cannot read property ...
It seems that when you leave the page, the map element no longer exists but the event bound to it is still there!...
Read more >Cannot read property 'overlayMouseTarget' of null-Googlemaps
Coding example for the question react-google-maps Uncaught TypeError: Cannot read property 'overlayMouseTarget' of null-Googlemaps.
Read more >Cannot read property 'overlayMouseTarget' of null
Uncaught TypeError : Cannot read property 'overlayMouseTarget' of null.
Read more >TypeError: Cannot read property 'map' of null in React.js
log(users); return ( <div> {/* ⛔️ users is `null` because API has not responded yet */} {/* ⛔️ Uncaught TypeError: Cannot read properties...
Read more >Cannot read properties of null (reading 'contains')error in react ...
TypeError : Cannot read properties of null (reading 'contains'), Need useEffect Cleanup,EventBubblingtypeerror cannot read property of null ...
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 Free
Top 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
Taking @foloinfo’s advice, I implemented the following class in my project that eliminates the errors. Hopefully this will help somebody else, too!
If it can help, after reading #405 , I added key={Math.random()} to
<OverlayView />
and the error message disappeared.I’m not sure if this is related but the
width
andheight
passed down togetPixelPositionOffset
is sometimes wrong. I receive (0px, 13px) whereas my markers are (24px, 32px). It leads to a misplaced overlay on the map.Here is the code with the GoogleMap component