-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathssr.tsx
62 lines (55 loc) · 1.87 KB
/
ssr.tsx
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Server-side HTML render
// Component to render the full HTML response in React
// ----------------------------------------------------------------------------
// IMPORTS
/* NPM */
import * as React from "react";
import { HelmetData } from "react-helmet";
// ----------------------------------------------------------------------------
// Types
export interface IHtmlProps {
css?: string;
js: string;
helmet: HelmetData;
html: string;
scripts?: string[];
styles?: Array<React.ReactElement<{}>>;
window?: {
[key: string]: object;
};
}
export default class Html extends React.PureComponent<IHtmlProps> {
public render() {
const { css, helmet, html, js, styles, window = {} } = this.props;
return (
<html lang="en" prefix="og: http://ogp.me/ns#" {...helmet.htmlAttributes.toString()}>
<head>
{helmet.title.toComponent()}
<meta charSet="utf-8" />
<meta httpEquiv="X-UA-Compatible" content="IE=edge" />
<meta httpEquiv="Content-Language" content="en" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
{helmet.meta.toComponent()}
{helmet.style.toComponent()}
{helmet.link.toComponent()}
{css && <link rel="stylesheet" href={css} />}
{styles}
{helmet.script.toComponent()}
{helmet.noscript.toComponent()}
</head>
<body {...helmet.bodyAttributes.toComponent()}>
<div id="root" dangerouslySetInnerHTML={{__html: html }} />
<script
dangerouslySetInnerHTML={{
__html: Object.keys(window).reduce(
(out, key) => out += `window.${key}=${JSON.stringify(window[key])};`,
"",
),
}
} />
</body>
<script src={js} />
</html>
);
}
}