Skip to content

Instantly share code, notes, and snippets.

@hswolff
Created April 29, 2020 13:27
Show Gist options
  • Select an option

  • Save hswolff/ec231e24696e66defccf49f15b77d544 to your computer and use it in GitHub Desktop.

Select an option

Save hswolff/ec231e24696e66defccf49f15b77d544 to your computer and use it in GitHub Desktop.

Revisions

  1. hswolff created this gist Apr 29, 2020.
    19 changes: 19 additions & 0 deletions lazyAnalytics.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    function useLazyAnalytics() {
    const [value, setValue] = useState(() => {
    return () => {
    const raceError = new Error('handler called before loaded');
    bugsnagClient.notify(raceError);
    };
    });

    useEffect(() => {
    import('./lazyAnalytics').then((mod) => {
    setValue(() => mod.default);
    });
    }, []);

    return value;
    }

    // usage
    const trackMongoNavAnalytics = useTrackMongoNavAnalytics();