Skip to content

Instantly share code, notes, and snippets.

@ardeearam
Created January 25, 2021 04:05
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 ardeearam/6e3940e4b621c3f4296f906a7be4a1dc to your computer and use it in GitHub Desktop.
Save ardeearam/6e3940e4b621c3f4296f906a7be4a1dc to your computer and use it in GitHub Desktop.
lib/GoogleLogin.js
export const loadGoogleScript = () => {
//loads the Google JavaScript Library
(function () {
const id = 'google-js';
const src = 'https://apis.google.com/js/platform.js';
//we have at least one script (React)
const firstJs = document.getElementsByTagName('script')[0];
//prevent script from loading twice
if (document.getElementById(id)) { return; }
const js = document.createElement('script');
js.id = id;
js.src = src;
js.onload = window.onGoogleScriptLoad;
firstJs.parentNode.insertBefore(js, firstJs);
}());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment