New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

create-react-microfrontend

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

create-react-microfrontend

Library that provides the ability to render a Create React App project within another React app.

  • 0.1.1
  • latest
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Create React MicroFrontEnd

Library that provides the ability to render a Create React App project within another React app.

Setup

1. Install

yarn add or npm install create-react-microfrontend

2. In the Create React App you want to be the micro frontend, in index.js:

import { createMicroFrontend } from 'create-react-microfrontend'

const reactRender = (renderProps, container) => {
    ReactDOM.render(
        <Router history={customHistory}>
            <App {...renderProps} />
        </Router>,
        container
    )
}

createMicroFrontend(
    reactRender,
    'POP', // App name
    false, // noMFE
    props, // localProps
    'root' // containerId
)

The reactRender function needs to be created to allow applying props from the parent app, and which component to apply them to. If, for instance, you had some further HOCs which wrapped around <App />. It also allows for the flexibility of applying props locally, for development pruposes.

To develop locally, in the third argument, pass true (the noMFE option), and it will render the app to the containerId provided, and will apply the supplied localProps to the reactRender function. This noMFE option would be a good place to use process.env.NODE_ENV === 'development'.

The appName will need to match the appName in the next step to retrieve the matching MFE.

3. useMicroFrontendReact in the parent application

Example :

import { useMicrofrontendReact } from 'create-react-microfrontend';

const [isLoaded, POP] = useMicrofrontendReact('POP', 'http://localhost:3000');

 React.useEffect(() => {
    if (!isLoaded) {
      return;
    }
    const { render, unmount } = POP;

    render(id, POPProps);
    return () => unmount(id);
  },              [isLoaded]);

useMicrofrontendReact(appName, microFrontendURL) returns isLoaded and the application functions of render(id, props) and unmount(id). Once the application is fetched, isLoaded returns true and the app can be rendered, and then unmount can be used in the cleanup as a returned function to a useEffect.

FAQs

Package last updated on 14 Sep 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc