2018-11-08 11:43:16 +00:00
|
|
|
import Document from 'next/document'
|
2017-05-07 12:25:33 +00:00
|
|
|
import { ServerStyleSheet } from 'styled-components'
|
2016-12-22 05:10:54 +00:00
|
|
|
|
|
|
|
export default class MyDocument extends Document {
|
2018-11-08 11:43:16 +00:00
|
|
|
static async getInitialProps (ctx) {
|
2017-05-07 12:25:33 +00:00
|
|
|
const sheet = new ServerStyleSheet()
|
2017-09-14 12:17:18 +00:00
|
|
|
|
2018-11-08 11:43:16 +00:00
|
|
|
const originalRenderPage = ctx.renderPage
|
|
|
|
ctx.renderPage = () => originalRenderPage({
|
|
|
|
enhanceApp: App => props => sheet.collectStyles(<App {...props} />)
|
|
|
|
})
|
|
|
|
|
|
|
|
const initialProps = await Document.getInitialProps(ctx)
|
|
|
|
return { ...initialProps, styles: [...initialProps.styles, ...sheet.getStyleElement()] }
|
2016-12-22 05:10:54 +00:00
|
|
|
}
|
2018-10-20 15:00:01 +00:00
|
|
|
}
|