Skip to content

Commit

Permalink
add support for passing parameters to remote components
Browse files Browse the repository at this point in the history
  • Loading branch information
hasanayan committed Mar 30, 2023
1 parent 4d9dd2b commit b3a9d2a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-dynamic-remote-component",
"version": "0.0.3",
"version": "0.0.4",
"description": "Allows you to dynamically load a component from a remote using webpack 5's module federation.",
"keywords": [
"react",
Expand Down
28 changes: 18 additions & 10 deletions src/RemoteComponent.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { FC } from "react";
import { attachScript } from "./attach-script";
import { loadModule } from "./load-module";
import { RemoteModule } from "./types";
import { suspend } from "./suspend";
import { RemoteModule } from "./types";
import { getRemoteModuleId } from "./utils";

export type RemoteComponentProps = RemoteModule & {
Expand Down Expand Up @@ -52,12 +51,21 @@ export const useRemoteModule = (remoteModule: RemoteModule) => {
return getModuleSuspended(remoteModule);
};

export const RemoteComponent: FC<RemoteComponentProps> = ({
unLoadScriptOnUnmount = true,
exportName = "default",
...remoteModule
}) => {
const { [exportName]: Component } = getModuleSuspended(remoteModule);
export function RemoteComponent<ExtraProps>(props: RemoteComponentProps) {
const {
unLoadScriptOnUnmount = true,
exportName = "default",
url,
scope,
module,
...componentProps
} = props;

return <Component />;
};
const { [exportName]: Component } = getModuleSuspended({
url,
scope,
module,
});

return <Component {...componentProps} />;
}

0 comments on commit b3a9d2a

Please sign in to comment.