weddingsite/pages/_document.js

38 lines
877 B
JavaScript
Raw Normal View History

2021-06-04 00:58:40 +00:00
import Document, { Html, Head, NextScript, Main } from 'next/document';
import { ServerStyleSheet } from 'styled-components';
export default class MyDocument extends Document {
static async getInitialProps(ctx) {
2021-06-04 00:58:40 +00:00
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();
}
2021-06-04 00:58:40 +00:00
}
render() {
return (
<Html lang="en-US">
<Head />
<body>
<Main />
<NextScript />
</body>
</Html>
);
}
}