Using injectScript inside a NextJs Host #529
-
Hello, I am trying to use Could you help me to understand what I am missing or doing bad 🙏 Remote app next.config.js:
Host app ./page/index.tsx :
and copied the
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
Hello, @SombreroElGringo. Hope you're doing well bro. I just made an example reproducing what you're trying to achieve Basically the problem is right after when you fetches the container and sets the state using the module loader function without calling it, a problem which I demonstrate here . In your case to solve it just apply the following changes to your index page in your host app 😄 useEffect(() => {
injectScript({
global: 'remote',
uniqueKey: 'remote',
url: 'http://localhost:4200/_next/static/chunks/remote.js',
})
.then((container) => container.get('./index'))
.then((data) => {
- setMicroFrontend(data);
+ setMicroFrontend(data().default);
});
}, []); And complementing, if you're using named exports just change the |
Beta Was this translation helpful? Give feedback.
Hello, @SombreroElGringo. Hope you're doing well bro.
I just made an example reproducing what you're trying to achieve
https://github.com/brunos3d/nextjs-federate-page
Basically the problem is right after when you fetches the container and sets the state using the module loader function without calling it, a problem which I demonstrate here .
In your case to solve it just apply the following changes to your index page in your host app 😄
useEffect(() => { injectScript({ global: 'remote', uniqueKey: 'remote', url: 'http://localhost:4200/_next/static/chunks/remote.js', }) .then((container) => container.get('./index')) .then((data) => { - setMicroF…