Skip to content

Commit 7f1d563

Browse files
committed
feat: Add RenderToBody support ssr
1 parent 12d6c86 commit 7f1d563

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/RenderToBody.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as React from "react";
22
import * as ReactDOM from "react-dom";
3+
import IS_NODE_ENV from "./common/nodeJS/IS_NODE_ENV";
34

45
export interface RenderToBodyProps {
56
style?: React.CSSProperties;
@@ -8,8 +9,10 @@ export interface RenderToBodyProps {
89
}
910

1011
export default class RenderToBody extends React.Component<RenderToBodyProps> {
11-
rootElm = document.createElement("div");
12+
rootElm = IS_NODE_ENV ? null : document.createElement("div");
13+
1214
componentDidMount() {
15+
if (IS_NODE_ENV) this.rootElm = document.createElement("div");
1316
const { style, className } = this.props;
1417
Object.assign(this.rootElm.style, style);
1518
if (className) this.rootElm.setAttribute("class", className);

0 commit comments

Comments
 (0)