Created
January 28, 2019 22:17
-
-
Save axross/ba3865b48291ed9b1b78d4293e6fc0f6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class A extends React.Component { | |
constructor(props, context) { | |
super(props, context); | |
this.globalCallbackName = 'kdjlwkqe'; | |
this.ref = React.createRef(); | |
} | |
componentDidMount() { | |
global[this.globalCallbackName] = () => new google.maps.Map(this.ref.current, { | |
center: {lat: -34.397, lng: 150.644}, | |
zoom: 8 | |
}); | |
} | |
componentWillUnmount() { | |
delete global[this.globalCallbackName]; | |
} | |
render() { | |
return <> | |
<div ref={this.ref}></div> | |
<script src={`https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&callback=${this.globalCallbackName}`}></script> | |
</>; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment