Giter Club home page Giter Club logo

Comments (13)

gregberge avatar gregberge commented on July 16, 2024 5

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.

mrasoahaingo avatar mrasoahaingo commented on July 16, 2024

Is this feature available on the latest version?

from loadable-components.

gregberge avatar gregberge commented on July 16, 2024

Yes!

from loadable-components.

mrasoahaingo avatar mrasoahaingo commented on July 16, 2024

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.

gregberge avatar gregberge commented on July 16, 2024

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.

mrasoahaingo avatar mrasoahaingo commented on July 16, 2024

Hum, so i need to resolve all loadable modules first before trying to access to static method?

from loadable-components.

gregberge avatar gregberge commented on July 16, 2024

Yes.

from loadable-components.

mrasoahaingo avatar mrasoahaingo commented on July 16, 2024

I get it now, thanks!

from loadable-components.

windFollower29 avatar windFollower29 commented on July 16, 2024

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.

gregberge avatar gregberge commented on July 16, 2024

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.

jsonchou avatar jsonchou commented on July 16, 2024

@neoziro

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.

jsonchou avatar jsonchou commented on July 16, 2024

thanks , i'll have a try.

from loadable-components.

davidfurlong avatar davidfurlong commented on July 16, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.