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:
parent
31feced24a
commit
b8291abeac
|
@ -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 () {
|
||||
|
|
Loading…
Reference in a new issue