You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
By reusing your own components you can save development time, keep your UI consistent across applications and let your whole team build together.
No need to create a UI library for reusable components across apps.
Create Shared UI App to create UI components. Deploy Shared UI App and Dynamically load a React Component from that URL using remote-component.
You can also add shared styles and common files in Shared App which you want to reuse.
How Remote Components works
The RemoteComponent React Component takes a URL as a prop. The URL is loaded and processed. This file must be a valid CommonJS Module that exports the component as default.
While the URL is loading, the fallback will be rendered. This is a similar pattern to React.Suspense. If no fallback is provided, then nothing will be rendered while loading.
Once loaded, there will either be an error a Component. The rendering will first be handled by the render callback function. If there is no render callback and err exists, a generic message will be shown.
The Component will be rendered either to the render callback if one exists, otherwise, it will be rendered as a standard component.
How Shared react components works
To use UI Components in all the apps you have to follow this for all the apps.
Remote Components will require some dependencies to be injected into them. At the minimum, we'll be injecting the React dependency.
The web application can include dependencies and inject them into the RemoteComponent. At a minimum, you will probably need the react dependency.
Create a file remote-component.config.js in the root of the web application.
If you are using any library or package that the Ui component is using then you have to add that dependency in this file.
ex: If you are using Material-UI to create a UI component then you have to add material-ui as a dependency in this file like this: ["@material-ui/core"]: require("@material-ui/core")