-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_document.js
30 lines (29 loc) · 838 Bytes
/
_document.js
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
import Document from "next/document";
//highlight-next-line
import { ServerStyleSheet } from "styled-components";
export default class MyDocument extends Document {
static async getInitialProps(ctx) {
//highlight-next-line
const sheet = new ServerStyleSheet();
const originalRenderPage = ctx.renderPage;
try {
ctx.renderPage = () =>
originalRenderPage({
//highlight-next-line
enhanceApp: App => props => sheet.collectStyles()
});
const initialProps = await Document.getInitialProps(ctx);
return {
...initialProps,
styles: (
<>
{initialProps.styles}
//highlight-next-line
{sheet.getStyleElement()}
)
};
} finally {
sheet.seal();
}
}
}