1
0
Fork 0
mirror of https://github.com/terribleplan/next.js.git synced 2024-01-19 02:48:18 +00:00

improve the styled-component example

This commit is contained in:
nkzawa 2016-12-22 17:10:17 +09:00
parent 31feced24a
commit b8291abeac

View file

@ -2,14 +2,11 @@ import Document, { Head, Main, NextScript } from 'next/document'
import styleSheet from 'styled-components/lib/models/StyleSheet'
export default class MyDocument extends Document {
static async getInitialProps (ctx) {
const renderPage = () => {
return ctx.renderPage()
}
const props = await Document.getInitialProps({ ...ctx, renderPage })
static async getInitialProps ({ renderPage }) {
styleSheet.flush()
const page = renderPage()
const style = styleSheet.rules().map(rule => rule.cssText).join('\n')
return { ...props, style }
return { ...page, style }
}
render () {