Last active
December 11, 2019 16:44
-
-
Save Bolza/3199030a427391f02b3cb37b1a8d5245 to your computer and use it in GitHub Desktop.
Lazy Loading error check
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
// 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