Skip to content

Instantly share code, notes, and snippets.

@joduplessis
Created June 2, 2019 07:53
Show Gist options
  • Save joduplessis/c142713d6e0c972eff06a2cb7fc224ad to your computer and use it in GitHub Desktop.
Save joduplessis/c142713d6e0c972eff06a2cb7fc224ad to your computer and use it in GitHub Desktop.
Nice simple React HOC for using Suspense with React Router's routes.
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