@yuskraft/remote-module-loader
v1.1.0
Published
A React hook for loading remote modules in Module Federation
Maintainers
Readme
Remote Module Loader
A badass React hook for loading remote modules dynamically. This package allows you to dynamically load remote components in your React application using Webpack's Module Federation.
https://github.com/user-attachments/assets/ab4102d0-9ebe-46db-85a0-3f0b7931a180
Table of Contents
Installation
To install the package, use npm or yarn:
npm install @yuskraft/remote-module-loaderor
yarn add @yuskraft/remote-module-loaderUsage
For a detailed usage example, check out our demo application.
Import the useLoadRemote hook and use it in your React component to load remote modules.
import { useLoadRemote } from '@yuskraft/remote-module-loader';
const MyComponent = () => {
const { Component, ready, hasError } = useLoadRemote({
url: 'https://example.com/remoteEntry.js',
scope: 'myRemote',
module: './MyRemoteComponent',
});
if (hasError) {
return <div>Error loading component</div>;
}
if (!ready) {
return <div>Loading...</div>;
}
return Component ? <Component /> : null;
};useLoadRemote(config: RemoteConfig): UseRemoteLoaderResult
Parameters:
config: An object with the following properties:url: The URL of the remote entry file.scope: The scope name of the remote module.module: The module name to load.
Returns:
- An object with the following properties:
Component: The loaded remote component, ornullif not yet loaded.ready: A boolean indicating if the component is ready to be used.hasError: A boolean indicating if there was an error loading the component.
- An object with the following properties:
Contributing
Contributions are welcome ! Please open an issue or submit a pull request !
