Skip to content

Is there a way to return a React Component from runtime's errorLoadRemote hook? #2053

Answered by ScriptedAlchemy
ryok90 asked this question in Q&A
Discussion options

You must be logged in to vote

Yes, you should be able to do that. I would use react lazy so you do not introduce eager dependencies.

    async errorLoadRemote({ id, error, from, origin }) {
      console.error(id, 'offline');
     const Header =  (await import('myLibrary/myComponent/header')).default

      const pg = header

      let mod;
      if (from === 'build') {
        mod = () => ({
          __esModule: true,
          default: pg,
        });
      } else {
        mod = {
          default: pg,
        };
      }

      return mod;
    },

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@ryok90
Comment options

Answer selected by ryok90
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants