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

[examples/react-jss] Add support for styled custom App component (#6094)

With the current example it's not possible to use any components with styles inside a custom App component.
 
Reference issue: cssinjs/jss#939
This commit is contained in:
Henri 2019-01-20 14:41:49 +01:00 committed by Tim Neutkens
parent b0a469233b
commit 02e44d13a9

View file

@ -3,16 +3,22 @@ import Document, { Head, Main, NextScript } from 'next/document'
import { SheetsRegistry, JssProvider } from 'react-jss'
export default class JssDocument extends Document {
static getInitialProps (ctx) {
static async getInitialProps (ctx) {
const registry = new SheetsRegistry()
const page = ctx.renderPage(App => props => (
<JssProvider registry={registry}>
<App {...props} />
</JssProvider>
))
const originalRenderPage = ctx.renderPage
ctx.renderPage = () =>
originalRenderPage({
enhanceApp: App => props => (
<JssProvider registry={registry}>
<App {...props} />
</JssProvider>
)
})
const initialProps = await Document.getInitialProps(ctx)
return {
...page,
...initialProps,
registry
}
}