Is there a way to return a React Component from runtime's errorLoadRemote hook? #2053
-
I want to return a default component whenever a remote fails to load through this runtime error hook. |
Beta Was this translation helpful? Give feedback.
Answered by
ScriptedAlchemy
Feb 1, 2024
Replies: 1 comment 1 reply
-
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;
}, |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
ryok90
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yes, you should be able to do that. I would use react lazy so you do not introduce eager dependencies.