-
-
Notifications
You must be signed in to change notification settings - Fork 380
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Attach static methods of wrapped component to loadable component #58
Comments
Is this feature available on the latest version? |
Yes! |
Actually i can't get the statics methods of the component nor the component it self :( Test.js
Main.js
Prints
|
Methods can't be added before the module is loaded. How could we know the methods? After the component being loaded, methods will be accessible. |
Hum, so i need to resolve all loadable modules first before trying to access to static method? |
Yes. |
I get it now, thanks! |
in ssr, how I can know that a loadable module has been loaded?
|
The only way to know if a component is rendered is in the component itself. The easiest method is to pass a function called when the component is mount. import loadable from '@loadable/component';
const Test = loadable(() => import('./Test'));
<Test onLoad={() => console.log('loaded')} /> // Test.js
import React, { useEffect } from 'react'
export default function Test({ onLoad }) {
useEffect(() => { onLoad() }, [])
return null
} |
client side:router config:
index page:../pages/Index/Index
server side:
my question:how can i get my static component.serverApiNames in server side. |
Loadable Components is not design to work with "statical" approach. I recommend you to use "react-navi" for this kind of approach. |
thanks , i'll have a try. |
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 const loadedComponent = await (component as DefaultImportedComponent<any>).load();
loadedComponent?.default?.accessYourStaticPropName |
Attach static methods of wrapped component to loadable component
c1.mjs
main.mjs
output:
Suggestion:
attach static methods or fields directly to loadable component ( c1 ):
preloadDataState method available by c1.preloadDataState instead of c1.Component.preloadDataState
The text was updated successfully, but these errors were encountered: