Skip to content

Instantly share code, notes, and snippets.

@ernestofreyreg
Created August 10, 2021 14:08
Show Gist options
  • Save ernestofreyreg/e4a6f44b63dd684cd7580140de152102 to your computer and use it in GitHub Desktop.
Save ernestofreyreg/e4a6f44b63dd684cd7580140de152102 to your computer and use it in GitHub Desktop.
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