Skip to content

Instantly share code, notes, and snippets.

@dearfrankg
Last active November 9, 2018 19:16
Show Gist options
  • Save dearfrankg/531540b88c2a6cbaab208d56fe68a331 to your computer and use it in GitHub Desktop.
Save dearfrankg/531540b88c2a6cbaab208d56fe68a331 to your computer and use it in GitHub Desktop.
styled-components
import Document, { Head, Main, NextScript } from "next/document";
import { ServerStyleSheet } from "styled-components";
export default class MyDocument extends Document {
static getInitialProps({ renderPage }) {
const sheet = new ServerStyleSheet();
const page = renderPage(App => props =>
sheet.collectStyles(<App {...props} />)
);
const styleTags = sheet.getStyleElement();
return { ...page, styleTags };
}
render() {
return (
<html>
<Head>
<title>nextjs project starter</title>
<meta
name="viewport"
content="initial-scale=1.0, width=device-width"
/>
{this.props.styleTags}
</Head>
<body>
<Main />
<NextScript />
</body>
</html>
);
}
}
@dearfrankg
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment