Last active
May 22, 2021 10:17
-
-
Save dipeshhkc/ac21c61516c74338c27d6d033279277e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Document, { Html, Head, Main, NextScript } from "next/document"; | |
import { SheetsRegistry, JssProvider, createGenerateId } from "react-jss"; | |
class MyDocument extends Document { | |
static async getInitialProps(ctx) { | |
const registry = new SheetsRegistry(); | |
const generateId = createGenerateId(); | |
const originalRenderPage = ctx.renderPage; | |
ctx.renderPage = () => | |
originalRenderPage({ | |
enhanceApp: (App) => (props) => ( | |
<JssProvider registry={registry} generateId={generateId}> | |
<App {...props} /> | |
</JssProvider> | |
), | |
}); | |
const initialProps = await Document.getInitialProps(ctx); | |
return { | |
...initialProps, | |
styles: ( | |
<> | |
{initialProps.styles} | |
<style id="server-side-styles">{registry.toString()}</style> | |
</> | |
), | |
}; | |
} | |
render() { | |
return ( | |
<Html> | |
<Head> | |
<link rel="icon" href="link to favicon" /> | |
<link href="link to font" rel="stylesheet"> | |
</Head> | |
<body> | |
<Main /> | |
<NextScript /> | |
</body> | |
</Html> | |
); | |
} | |
} | |
export default MyDocument; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Line 32 requires a slash:
<link href="link to font" rel="stylesheet" />