-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_document.tsx
52 lines (45 loc) · 1.27 KB
/
_document.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
import { createDOMRenderer, renderToStyleElements } from '@fluentui/react-components';
import Document, { Html, Head, Main, NextScript, DocumentContext } from 'next/document';
class MyDocument extends Document {
static async getInitialProps(ctx: DocumentContext) {
// 👇 creates a renderer that will be used for SSR
const renderer = createDOMRenderer();
const originalRenderPage = ctx.renderPage;
ctx.renderPage = () =>
originalRenderPage({
enhanceApp: App =>
function EnhancedApp(props) {
const enhancedProps = {
...props,
// 👇 this is required to provide a proper renderer instance
renderer,
};
return <App {...enhancedProps} />;
},
});
const initialProps = await Document.getInitialProps(ctx);
const styles = renderToStyleElements(renderer);
return {
...initialProps,
styles: (
<>
{initialProps.styles}
{/* 👇 adding Fluent UI styles elements to output */}
{styles}
</>
),
};
}
render() {
return (
<Html>
<Head />
<body>
<Main />
<NextScript />
</body>
</Html>
);
}
}
export default MyDocument;