You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
1.1 KiB
38 lines
1.1 KiB
import Document, { DocumentInitialProps, DocumentContext } from 'next/document'; |
|
import { ServerStyleSheets as MaterialUiServerStyleSheets } from '@material-ui/styles'; |
|
// import { ServerStyleSheet as StyledComponentSheets } from 'styled-components'; |
|
|
|
class MyDocument extends Document { |
|
static async getInitialProps( |
|
ctx: DocumentContext, |
|
): Promise<DocumentInitialProps> { |
|
const materialUiSheets = new MaterialUiServerStyleSheets(); |
|
const originalRenderPage = ctx.renderPage; |
|
|
|
ctx.renderPage = () => |
|
originalRenderPage({ |
|
/* eslint-disable react/display-name */ |
|
enhanceApp: (App) => (props) => |
|
materialUiSheets.collect( |
|
<App |
|
/* eslint-disable react/jsx-props-no-spreading */ |
|
{...props} |
|
/>, |
|
), |
|
}); |
|
|
|
const initialProps = await Document.getInitialProps(ctx); |
|
|
|
return { |
|
...initialProps, |
|
styles: ( |
|
<> |
|
{initialProps.styles} |
|
{materialUiSheets.getStyleElement()} |
|
</> |
|
), |
|
}; |
|
} |
|
} |
|
|
|
export default MyDocument;
|
|
|