2018-09-12 13:49:54 +00:00
|
|
|
import React from 'react'
|
|
|
|
import Document, { Head, Main, NextScript } from 'next/document'
|
2019-02-04 10:51:38 +00:00
|
|
|
import { SheetsRegistry, JssProvider, createGenerateId } from 'react-jss'
|
2018-09-12 13:49:54 +00:00
|
|
|
|
|
|
|
export default class JssDocument extends Document {
|
2019-01-20 13:41:49 +00:00
|
|
|
static async getInitialProps (ctx) {
|
2018-09-12 13:49:54 +00:00
|
|
|
const registry = new SheetsRegistry()
|
2019-02-04 10:51:38 +00:00
|
|
|
const generateId = createGenerateId()
|
2019-01-20 13:41:49 +00:00
|
|
|
const originalRenderPage = ctx.renderPage
|
|
|
|
ctx.renderPage = () =>
|
|
|
|
originalRenderPage({
|
|
|
|
enhanceApp: App => props => (
|
2019-02-04 10:51:38 +00:00
|
|
|
<JssProvider registry={registry} generateId={generateId}>
|
2019-01-20 13:41:49 +00:00
|
|
|
<App {...props} />
|
|
|
|
</JssProvider>
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
const initialProps = await Document.getInitialProps(ctx)
|
2018-09-12 13:49:54 +00:00
|
|
|
|
|
|
|
return {
|
2019-01-20 13:41:49 +00:00
|
|
|
...initialProps,
|
2018-09-12 13:49:54 +00:00
|
|
|
registry
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
render () {
|
|
|
|
return (
|
|
|
|
<html>
|
|
|
|
<Head>
|
|
|
|
<style id='server-side-styles'>
|
|
|
|
{this.props.registry.toString()}
|
|
|
|
</style>
|
|
|
|
</Head>
|
|
|
|
|
|
|
|
<body>
|
|
|
|
<Main />
|
|
|
|
<NextScript />
|
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|