DEV Community

The Complete Guide to Micro Frontend with React.js for 2025

Rahul Sharma on March 17, 2022

What is a micro frontend? The Micro Frontend style of architecture design does for the frontend of an application what microservices d...
Collapse
 
eggm4n profile image
Luke

Just testing this out and found it a lot easier than I expected, thank you this is a very neat article.

How would you address security concerns like seamlessly managing authentication & access control across multiple distributed apps?

How would you control/restrict who can add your export as a remote?

Collapse
 
devsmitra profile image
Rahul Sharma

content security policy you can use.

Collapse
 
tayejoseph profile image
Taye

Thank you very much for the article, was really helpful

Collapse
 
chema profile image
José María CL

Simple, Easy, Useful. Than you a lot!

Collapse
 
almangor profile image
Alex • Edited

Out of curiosity:

  1. exposes: All the component names that you want to expose to the container app.

How to expose multiple components from the same "remote" app? And what if the "container" would be on Angular?

Collapse
 
devsmitra profile image
Rahul Sharma • Edited

// React app => inject.js

const toReactApp = (el) => ReactDOM.render(<Counter />, el);
export default toReactApp;
Enter fullscreen mode Exit fullscreen mode

// webpack.config.js

exposes: {
        "./Counter": "./src/components/Counter",
        "./Counter1": "./src/components/Counter1",
        './toReactApp': './src/inject.js',
}
Enter fullscreen mode Exit fullscreen mode

// Angular

import toReactApp from './<path>/toReactApp'

@Component({
    selector: 'app',
    template: ` <div #myDiv>Some text</div>`,
})
export class AppComponent implements AfterViewInit {
    @ViewChild('myDiv') myDiv: ElementRef;

    ngAfterViewInit() {
        toReactApp(this.myDiv.nativeElement);
    }
}
Enter fullscreen mode Exit fullscreen mode

I'm not angular expert, but I think you can use it like that.

Collapse
 
himedlooff profile image
Mike Morici

Any special setup if you were to use different versions of react for the host app vs the child app?

Collapse
 
devsmitra profile image
Rahul Sharma • Edited

No special setup required

Worst case: you can inject micro-frontend app to ref. This is valid solution when you want to use 2 different framework for microfrontend.

Collapse
 
artur_sopelnik_fe02383a86 profile image
Artur Sopelnik

medium.com/design-systems-collecti...

Here you could find a great way to do that.

Collapse
 
shivampawar profile image
Shivam Pawar

Could you please confirm if we need react Lazy Loading to render micro frontend app inside container?

Collapse
 
devsmitra profile image
Rahul Sharma

Yes, we can do that.