Skip to content

Instantly share code, notes, and snippets.

@BetterProgramming
Created April 7, 2020 23:58
Show Gist options
  • Save BetterProgramming/320d5b74494f37fd544000ef193f1523 to your computer and use it in GitHub Desktop.
Save BetterProgramming/320d5b74494f37fd544000ef193f1523 to your computer and use it in GitHub Desktop.

Revisions

  1. BetterProgramming created this gist Apr 7, 2020.
    13 changes: 13 additions & 0 deletions useEffect.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,13 @@
    import { useEffect } from 'react';
    const importScript = resourceUrl=> {
    useEffect(() => {
    const script = document.createElement('script');
    script.src = resourceUrl;
    script.async = true;
    document.body.appendChild(script);
    return () => {
    document.body.removeChild(script);
    }
    }, [resourceUrl]);
    };
    export default importScript;