Skip to content

Instantly share code, notes, and snippets.

@hswolff
Created April 29, 2020 13:27
Show Gist options
  • Save hswolff/ec231e24696e66defccf49f15b77d544 to your computer and use it in GitHub Desktop.
Save hswolff/ec231e24696e66defccf49f15b77d544 to your computer and use it in GitHub Desktop.
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();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment