Comments (13)
Loadable Components is not design to work with "statical" approach. I recommend you to use "react-navi" for this kind of approach.
from loadable-components.
Is this feature available on the latest version?
from loadable-components.
Yes!
from loadable-components.
Actually i can't get the statics methods of the component nor the component it self :(
Test.js
import React from 'react';
const Test = () => <h1>Test</h1>;
Test.staticMethod = () => console.log('test');
export default Test;
Main.js
import loadable from '@loadable/component';
const Test = loadable(() => import('./Test'));
console.log(Test);
console.log(Test.Component);
console.log(Test.staticMethod);
Prints
// { '$$typeof': Symbol(react.forward_ref), render: [Function], preload: [Function] }
// undefined
// undefined
from loadable-components.
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.
from loadable-components.
Hum, so i need to resolve all loadable modules first before trying to access to static method?
from loadable-components.
Yes.
from loadable-components.
I get it now, thanks!
from loadable-components.
in ssr, how I can know that a loadable module has been loaded? loadableReady()
must be called in browser only . @neoziro
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.
from loadable-components.
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
}
from loadable-components.
client side:
router config:
{
path: `/index`,
exact: true,
page: 'Index',
meta: {
title: 'aaaaa'
},
component: loadable(props => {
return import(/* webpackChunkName: "Index" */
`../pages/Index/Index`)
})
},
index page:
../pages/Index/Index
class IndexPage extends Component {
// ...
}
IndexPage.serverApiNames = "indexApi,commonApi" //static properties,
server side:
let currentRoute = routes[0].routes.find(router =>
matchPath(ctx.request.path, {
path: router.path,
exact: router.exact
})
)
let { exact, page, meta, component } = currentRoute
my question:
how can i get my static component.serverApiNames in server side.
from loadable-components.
thanks , i'll have a try.
from loadable-components.
how can i get my static component.serverApiNames in server side.
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
from loadable-components.
Related Issues (20)
- problem with redial HOT 2
- How to change referencing external styles to preload mode
- Fallback running even when component has previously loaded HOT 1
- Webpack doesn't like @loadable/server 5.16.4 HOT 5
- Server is caching old request split chunks, and these are not being re-requested when a new request is made to the server.
- ctor.requireAsync is not a function error HOT 1
- Inline Chunk injection HOT 2
- Not working with latest @loadable/server & @loadable/babel-plugin `v5.16.0` version HOT 4
- How to lazyload a hook? HOT 3
- Fallback behaviour HOT 1
- Main.js is rendered on every page even if I splitted each page into chunks with @loadable/component
- error in ./node_modules/@loadable/component/dist/loadable.esm.mjs HOT 9
- Why ChunkExtractor is required? HOT 3
- Is website sync with repo?
- If I am using react18, do I still need loadable-components HOT 6
- Add esbuild support HOT 3
- react-native-web SSR support HOT 1
- Loading state is always true on first render HOT 3
- Add query parameter support HOT 3
- SSR is broken for component v5.16.2+ HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from loadable-components.