0.0.3 • Published 3 years ago

@monolithed/lazy-service v0.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

@monolithed/lazy-service

Build Status License

Lazy Service is a wrapper around several scripts to support the Module Federation conception.

Installation

Install with npm or Yarn:

npm:

npm install @monolithed/lazy-service --save

Yarn:

yarn add @monolithed/lazy-service

Basic usage

import React, {
    FunctionComponent,
    Suspense,
    lazy
} from 'react';

import {
    useScript,
    componentLoader,
    ErrorBoundary
} from '@monolithed/lazy-service';

type Props = {
    src: string;
    scope: string;
    module: string;
};

const LazyService: FunctionComponent<Props> = ({children, src, scope, module}): JSX.Element => {
    const {loaded, failed} = useScript({src});
    const remoteModule = componentLoader({scope, module});

    const RemoteComponent = lazy(remoteModule);

    return (
        <ErrorBoundary>
            <Suspense fallback="loading...">
                <RemoteComponent>{...children.props}</Component>
            </Suspense>
        </ErrorBoundary>
    );
};

Publishing

npm publish --access public --verbose

License

MIT

Contributing

Feel free to submit a pull request if you find any bugs. Please make sure all commits are properly documented.