forked from module-federation/module-federation-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadapter.js
More file actions
39 lines (35 loc) · 961 Bytes
/
adapter.js
File metadata and controls
39 lines (35 loc) · 961 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import React from "react";
class Adapter extends React.Component {
constructor(props) {
super(props);
this.refHold;
}
init = (hydrate) => {
(async () => {
const ReactDOM = (await import("app2/newReactDOM")).default;
const React = (await import("app2/newReact")).default;
const RemoteComponent = await this.props.importer();
const { importer, children, ...rest } = this.props;
const renderMethod = hydrate ? ReactDOM.hydrate : ReactDOM.render;
renderMethod(
React.createElement(RemoteComponent.default, rest, children),
this.refHold
);
})();
};
componentDidUpdate(prevProps, prevState, snapshot) {
this.init(true);
}
componentDidMount() {
this.init();
}
render() {
return (
<div
style={{ border: "1px red solid", padding: "10px", margin: "20px 0" }}
ref={(ref) => (this.refHold = ref)}
/>
);
}
}
export default Adapter;