Created
May 4, 2021 13:26
-
-
Save kosciolek/10d3566ac56d5c33512fed052753647a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Document, { Html, Head, Main, NextScript } from "next/document"; | |
import { ServerStyleSheet } from "styled-components"; | |
class MyDocument extends Document { | |
static async getInitialProps(ctx) { | |
const sheet = new ServerStyleSheet(); | |
const originalRenderPage = ctx.renderPage; | |
ctx.renderPage = () => | |
originalRenderPage({ | |
enhanceApp: App => props => sheet.collectStyles(<App {...props} />) | |
}); | |
const styleTags = sheet.getStyleElement(); | |
const initialProps = await Document.getInitialProps(ctx); | |
return { styleTags, ...initialProps }; | |
} | |
render() { | |
return ( | |
<Html> | |
<Head /> | |
<body> | |
<Main /> | |
<NextScript /> | |
</body> | |
</Html> | |
); | |
} | |
} | |
export default MyDocument; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment