Usage with HOC loading
See original GitHub issueJust a tip on how to use this library together with a HOC-loader like redux-connect
:
// Your wrapped component
const MyAsyncComponent = loadable(() => import('./MyAsyncComponent/MyAsyncComponent'))
// Utility to extract the wrapped component if loadable-HOC will conflict with your other HOCs
const loadableWrapper = (cb, LoadableComponent) => {
LoadableComponent.load().then((Comp) => {
cb(null, Comp)
}).catch((error) => {
console.log('Error loading', error)
})
}
<Route path='/some-path' getComponent={(nextState, cb) => loadableWrapper(cb, MyAsyncComponent)} />
Issue Analytics
- State:
- Created 6 years ago
- Comments:24
Top Results From Across the Web
Handle loadings in React by using Higher Order Components
Handle loadings in React by using Higher Order Components · Higher Order Component (HOC) · Loading a List · Put it into Action...
Read more >Building a Universal Higher-Order Component Page Loader ...
The code for the loading HOC isn't very complicated, in actuality. Here's a code snippet of the universal loader component my team uses...
Read more >Higher-Order Components - React
A higher-order component (HOC) is an advanced technique in React for reusing component logic. HOCs are not part of the React API, per...
Read more >Usage with HOC loading · Issue #15 · gregberge/loadable ...
Hi. Is this still the right way to work with asyncConnect'ed components? It seems like the load() method is not available on the...
Read more >How to show a loader via HOC? - Stack Overflow
I want to use a HOC component to display a loading animation. Some components have the prop "isLoading" and others "isPending".
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Later discovered that for SSR intial render we need to extract loadable-id and set a loadable key on the loaded component. If not the component would not be included in the script-tag, and you will have a flicker with nothing on the screen after intial SSR render while client-side is taking over. I use Preact and Preact-compat in production and it works fine now.
The above code is with react-router v3, but with react-router v4 (and redux-connect) combining both the async Hoc and make the container lazyload is not possible. You need to re-organize your code having the Hoc above, and inside it lazyload the View with all heavy dendencies, like this: