Created
April 29, 2020 13:27
-
-
Save hswolff/ec231e24696e66defccf49f15b77d544 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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