Skip to content

Instantly share code, notes, and snippets.

@eldh
Created January 3, 2020 09:06
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save eldh/6263cc738d02d977a216ca0c199dd3d4 to your computer and use it in GitHub Desktop.
Save eldh/6263cc738d02d977a216ca0c199dd3d4 to your computer and use it in GitHub Desktop.
import React from 'react'
export function makeLoadable({ loading, render, loader }) {
const Comp = render
? React.lazy(() =>
loader().then(loaded => ({
...loaded,
default: props => render(loaded, props),
}))
)
: React.lazy(loader)
return props => (
<React.Suspense fallback={loading}>
<Comp {...props} />
</React.Suspense>
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment