Files: 04f1928b97e35d5d5fe0cd9c216f1e431a121f33 / pages / _document.tsx
1051 bytesRaw
1 | import Document, { Html, Head, Main, NextScript } from 'next/document'; |
2 | import { ServerStyleSheet } from 'styled-components'; |
3 | |
4 | class MyDocument extends Document { |
5 | static async getInitialProps(ctx) { |
6 | const sheet = new ServerStyleSheet(); |
7 | const originalRenderPage = ctx.renderPage; |
8 | const initialProps = await Document.getInitialProps(ctx); |
9 | |
10 | try { |
11 | ctx.renderPage = () => |
12 | originalRenderPage({ |
13 | enhanceApp: App => props => sheet.collectStyles(<App {...props} />), |
14 | }) |
15 | |
16 | const initialProps = await Document.getInitialProps(ctx) |
17 | return { |
18 | ...initialProps, |
19 | styles: ( |
20 | <> |
21 | {initialProps.styles} |
22 | {sheet.getStyleElement()} |
23 | </> |
24 | ), |
25 | } |
26 | } finally { |
27 | sheet.seal() |
28 | } |
29 | |
30 | return { |
31 | ...initialProps |
32 | }; |
33 | } |
34 | |
35 | render() { |
36 | return ( |
37 | <Html lang="en"> |
38 | <Head> |
39 | </Head> |
40 | <body> |
41 | <Main /> |
42 | <NextScript /> |
43 | </body> |
44 | </Html> |
45 | ) |
46 | } |
47 | } |
48 | |
49 | export default MyDocument; |
50 | |
51 |
Built with git-ssb-web