Created
June 2, 2019 07:53
-
-
Save joduplessis/c142713d6e0c972eff06a2cb7fc224ad to your computer and use it in GitHub Desktop.
Nice simple React HOC for using Suspense with React Router's routes.
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
import React from 'react' | |
import LoadingComponent from 'loading.component' | |
export default (fn, props) => { | |
const Component = React.lazy(fn) | |
return <React.Suspense fallback={<LoadingComponent />}><Component {...props} /></React.Suspense> | |
} | |
/** | |
* Example usage: | |
* | |
* import loadComponent from 'load.component' | |
* | |
* <Route path="/auth" render={props => loadComponent(() => import("./pages/auth.page"), props)} /> | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment