Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
tool to load Google Maps API
import load from "little-loader";
import qs from "query-string";
// YOUR_API_KEY - string
// libraries - array of strings, eg ['places']
const loadGoogleMaps = (YOUR_API_KEY, libraries) => {
return new Promise( (resolve, reject) => {
var params = {key: YOUR_API_KEY, libraries: libraries}
load(`https://maps.googleapis.com/maps/api/js?${qs.stringify(params)}`, (error) => {
if (error) {
reject("Unable to load Google Maps");
} else {
console.log('Google Maps loaded.')
resolve();
}
})
})
}
export default loadGoogleMaps;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment