Files
web2.0-frontend/src/pages/_document.tsx
T
2020-12-02 02:17:44 +02:00

44 lines
1.0 KiB
TypeScript

import React from "react";
import Document, {
Html, Head, Main, NextScript, DocumentContext,
} from "next/document";
import { ServerStyleSheet } from "styled-components";
export default class MyDocument extends Document {
static async getInitialProps(ctx: DocumentContext) {
const sheet = new ServerStyleSheet();
const originalRenderPage = ctx.renderPage;
try {
ctx.renderPage = () => originalRenderPage({
enhanceApp: (App) => (props) => sheet.collectStyles(<App {...props} />),
});
const initialProps = await Document.getInitialProps(ctx);
return {
...initialProps,
styles: (
<>
{initialProps.styles}
{sheet.getStyleElement()}
</>
),
};
} finally {
sheet.seal();
}
}
render() {
const { styleTags } = this.props as any;
return (
<Html lang="fi">
<Head />
<body>
{styleTags}
<Main />
<NextScript />
</body>
</Html>
);
}
}