Attach static methods of wrapped component to loadable component
See original GitHub issueAttach static methods of wrapped component to loadable component
c1.mjs
import * as React from 'react'
const createElement = React.default.createElement
const Component = React.default.Component
export default class c1 extends Component {
constructor( props ){
super( props )
}
render(){
return createElement( 'p', {}, 'hello' )
}
static async preloadDataState( parameters ){
debugger
}
}
main.mjs
import * as React from 'react'
const createElement = React.default.createElement
import * as LoadableComponents from 'loadable-components'
const loadable = LoadableComponents.default.default
import * as LoadableComponentsServer from 'loadable-components/server'
const getLoadableState = LoadableComponentsServer.default.getLoadableState
const c1 = loadable( () => import( /* webpackChunkName: "main.c1" */ './c1.mjs' ), {
modules: [ './c1.mjs' ],
} )
const composition = createElement( c1 )
getLoadableState( composition ).then( ls => {
console.log( c1.Component.preloadDataState )
} )
output:
[AsyncFunction: preloadDataState]
Suggestion: attach static methods or fields directly to loadable component ( c1 ): preloadDataState method available by c1.preloadDataState instead of c1.Component.preloadDataState
Issue Analytics
- State:
- Created 5 years ago
- Comments:13 (5 by maintainers)
Top Results From Across the Web
Using React Loadable for Code Splitting by Components and ...
We pass a function as a value to loader which returns the Hello component we created earlier, and we make use of import()...
Read more >Loadable Components
This is a function that receives the imported module (what the import() call resolves to) and the props, and returns the component.
Read more >Why when a component is wrapped inside a High Order ...
The reason static values aren't available when using a higher order component (for example, enhance in the example below) is because the ...
Read more >How To Create Wrapper Components in React with Props
You'll learn to split data and refactor components as you create flexible wrapping components. By the end of this tutorial, you'll have a ......
Read more >Introduction to Higher-Order Components in React by example
Don't Use HOCs inside the render method; Static methods must be copied ... Rather, a HOC composes the original component by wrapping it...
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
Loadable Components is not design to work with “statical” approach. I recommend you to use “react-navi” for this kind of approach.
this seems to be possible now - if you know which Loadable component is loading via a route match (react router or otherwise)
you can do