From b8291abeaca54f4b2640b7bcc5ec98bedb250423 Mon Sep 17 00:00:00 2001 From: nkzawa Date: Thu, 22 Dec 2016 17:10:17 +0900 Subject: [PATCH] improve the styled-component example --- examples/with-styled-components/pages/_document.js | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/examples/with-styled-components/pages/_document.js b/examples/with-styled-components/pages/_document.js index 5175c134..6e4b288f 100644 --- a/examples/with-styled-components/pages/_document.js +++ b/examples/with-styled-components/pages/_document.js @@ -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 () {