Loadable-components: integration with React Router Config

Created on 8 Mar 2019  ·  3Comments  ·  Source: gregberge/loadable-components

💬 Questions and Help

  • Read carefully the README of the project
    Done!
  • Search if your answer has already been answered in old issues
    Done!

I got a little used React-Router-Config's technology:

matchRoutes(routes, url).map(({route, match}) => {
        let {getInitData} = route.component; // component's static method
        return getInitData instanceof Function
            ? getInitData(match, store)
            : Promise.resolve(null)
    });

console.log(route.component) //

 { '$$typeof': Symbol(react.forward_ref),
  render: [Function],
  preload: [Function] }

Is it possible to access the component's static method getInitData, dynamically imported by loadable-components in routes?

question ❓

Most helpful comment

No - an underlying component is not actually loaded at this moment, but would be in a future, when you render a loadable wrapper around it.

If you want to keep using this pattern(I also very like it) - extract “getInitData” to a separate file.

Then:

const component=loadable(()=>import(...);
component.getInitData = getInitData;

All 3 comments

No - an underlying component is not actually loaded at this moment, but would be in a future, when you render a loadable wrapper around it.

If you want to keep using this pattern(I also very like it) - extract “getInitData” to a separate file.

Then:

const component=loadable(()=>import(...);
component.getInitData = getInitData;

And it should work on the server?
interesting solution..
Thanks!

Hello @valorloff, @theKashey solution is good, it should work.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

gcardella picture gcardella  ·  7Comments

ksntcrq picture ksntcrq  ·  7Comments

salzhrani picture salzhrani  ·  3Comments

ghost picture ghost  ·  4Comments

gregberge picture gregberge  ·  7Comments