Skip to content

Instantly share code, notes, and snippets.

@Bolza
Last active December 11, 2019 16:44
Show Gist options
  • Save Bolza/3199030a427391f02b3cb37b1a8d5245 to your computer and use it in GitHub Desktop.
Save Bolza/3199030a427391f02b3cb37b1a8d5245 to your computer and use it in GitHub Desktop.
Lazy Loading error check
// inspired by https://dev.to/goenning/how-to-retry-when-react-lazy-fails-mb5
const ValueSet = React.lazy(() =>
lazyCheck(() => import('../routes/ValueSet/ValueSet'))
)
function lazyCheck(fn: Function): Promise<{ default: ComponentType<any> }> {
return new Promise((resolve, reject) => {
fn()
.then(resolve)
.catch((error: Error) => {
console.log('catching w/ lazy loading', error)
})
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment