| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
parent directory.. | ||||
For an example implementation of using different React versions together with Module Federation, check out the runtime plugin folder runtime-plugins/multiple-react-versions.
This example demos the ability to load two separate versions of react (v16.6.3 and v16.13.1).
Check the typescript version of this example here.
Module Federation allows us to create an adapter which attaches a hooks-friendly version to render a section of thr app using modern versions.
Run pnpm run start. This will build and serve both app1 and app2 on ports 3001 and 3002 respectively.
This example contains two important components, the ReactAdapterConsumer and ReactAdapterProvider. They are responsible to make the two versions of react work together.
The adapter consumes both versions of react to "translate" the props into a fresh render. This could be presented as a HOC or federated components could have a legacy export containing the adapter build in.
This component is responsible to dynamic render/hydrate the federated component using it host version of React.
You can see the usage here.
import React from 'react';
const Button = props => {
return <button style={{ color: props.color }}>Click me</button>;
};
export const Adapted = React.forwardRef((props, ref) => {
return <ReactAdapterProvider component={Button} color="red" ref={ref} />;
});This component is responsible to render the federated component using the remote version of React.
You can see the usage here.
<ReactAdapterConsumer
color="blue"
fallback={<div>Loading...</div>}
importer={() => import('app2/Button').then(module => ({ default: module.Adapted }))}
/>"Best Practices, Rules amd more interesting information here
| Back | FazBrowse Home | New Git URL |