Skip to content

Instantly share code, notes, and snippets.

@axross
Created January 28, 2019 22:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save axross/ba3865b48291ed9b1b78d4293e6fc0f6 to your computer and use it in GitHub Desktop.
Save axross/ba3865b48291ed9b1b78d4293e6fc0f6 to your computer and use it in GitHub Desktop.
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