Commit b8291abe authored by nkzawa's avatar nkzawa

improve the styled-component example

parent 31feced2
...@@ -2,14 +2,11 @@ import Document, { Head, Main, NextScript } from 'next/document' ...@@ -2,14 +2,11 @@ import Document, { Head, Main, NextScript } from 'next/document'
import styleSheet from 'styled-components/lib/models/StyleSheet' import styleSheet from 'styled-components/lib/models/StyleSheet'
export default class MyDocument extends Document { export default class MyDocument extends Document {
static async getInitialProps (ctx) { static async getInitialProps ({ renderPage }) {
const renderPage = () => { styleSheet.flush()
return ctx.renderPage() const page = renderPage()
}
const props = await Document.getInitialProps({ ...ctx, renderPage })
const style = styleSheet.rules().map(rule => rule.cssText).join('\n') const style = styleSheet.rules().map(rule => rule.cssText).join('\n')
return { ...props, style } return { ...page, style }
} }
render () { render () {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment