53 lines
1.8 KiB
TypeScript
53 lines
1.8 KiB
TypeScript
|
import Document, {
|
||
|
Html, Head, Main, NextScript,
|
||
|
} from 'next/document'
|
||
|
import { ServerStyleSheet } from 'styled-components'
|
||
|
|
||
|
export default class MyDocument extends Document {
|
||
|
static async getInitialProps(ctx) {
|
||
|
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()
|
||
|
}
|
||
|
}
|
||
|
render() {
|
||
|
return (
|
||
|
<Html>
|
||
|
<Head>
|
||
|
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet" />
|
||
|
<link rel="icon" href="/icon.png" type="image/png"/>
|
||
|
<script src="https://unpkg.com/react-bootstrap@next/dist/react-bootstrap.min.js" crossorigin></script>
|
||
|
<link
|
||
|
rel="stylesheet"
|
||
|
href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css"
|
||
|
integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk"
|
||
|
crossorigin="anonymous"
|
||
|
/>
|
||
|
</Head>
|
||
|
<body>
|
||
|
<Main />
|
||
|
<NextScript />
|
||
|
</body>
|
||
|
</Html>
|
||
|
);
|
||
|
}
|
||
|
}
|