I have been trying to import an external library (google Maps) in order to use it in a React component
index.html file
<div id="app"></div>
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=MY_API_KEY_GOES_HERE&callback=initMap" async defer>
react file
componentDidMount() {
this.map = new google.maps.Map(this.refs.map, {
center: {lat: this.props.lat, lng: this.props.lng},
zoom: 8
});
}
render() {
return <div>
<p>I am a map component</p>
<div id="map" ref="map"/>
</div>
}
The error I get is:
Uncaught ReferenceError: google is not defined
I have tried everything but nothing seems to be working. How do I access the variable from this script inside my component?
This is just an example, please do not tell me to use one of the NPM packages for React Google Maps.
Thanks, Harris