_document.js 771 B

1234567891011121314151617181920212223242526272829
  1. import React from 'react';
  2. import Document, { Head, Main, NextScript } from 'next/document';
  3. import { ServerStyleSheet } from 'styled-components';
  4. class MyDocument extends Document {
  5. static getInitialProps({ renderPage }) {
  6. const sheet = new ServerStyleSheet();
  7. const page = renderPage(App => props => sheet.collectStyles(<App {...props} />));
  8. const styleTags = sheet.getStyleElement();
  9. return { ...page, styleTags };
  10. }
  11. render() {
  12. return (
  13. <html lang="en">
  14. <Head>
  15. <link rel="shortcut icon" type="image/x-icon" href="/static/favicon.ico" />
  16. {this.props.styleTags}
  17. </Head>
  18. <body>
  19. <Main />
  20. <NextScript />
  21. </body>
  22. </html>
  23. );
  24. }
  25. }
  26. export default MyDocument;