Created
August 10, 2021 14:08
-
-
Save ernestofreyreg/e4a6f44b63dd684cd7580140de152102 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 * as React from 'react' | |
import Document, { Html, Head, Main, NextScript } from 'next/document' | |
import { ServerStyleSheets } from '@material-ui/core/styles' | |
export default class MySaaSDocument extends Document { | |
render() { | |
return ( | |
<Html lang='en'> | |
<Head> | |
<link | |
rel='stylesheet' | |
href='https://fonts.googleapis.com/css?family=Roboto:300,400,500,700&display=swap' | |
/> | |
</Head> | |
<body> | |
<Main /> | |
<NextScript /> | |
</body> | |
</Html> | |
) | |
} | |
} | |
MySaaSDocument.getInitialProps = async ctx => { | |
const sheets = new ServerStyleSheets() | |
const originalRenderPage = ctx.renderPage | |
ctx.renderPage = () => | |
originalRenderPage({ | |
enhanceApp: App => props => sheets.collect(<App {...props} />) | |
}) | |
const initialProps = await Document.getInitialProps(ctx) | |
return { | |
...initialProps, | |
styles: [...React.Children.toArray(initialProps.styles), sheets.getStyleElement()] | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment