提交 02e44d13 编写于 作者: H Henri 提交者: Tim Neutkens

[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
上级 b0a46923
...@@ -3,16 +3,22 @@ import Document, { Head, Main, NextScript } from 'next/document' ...@@ -3,16 +3,22 @@ import Document, { Head, Main, NextScript } from 'next/document'
import { SheetsRegistry, JssProvider } from 'react-jss' import { SheetsRegistry, JssProvider } from 'react-jss'
export default class JssDocument extends Document { export default class JssDocument extends Document {
static getInitialProps (ctx) { static async getInitialProps (ctx) {
const registry = new SheetsRegistry() const registry = new SheetsRegistry()
const page = ctx.renderPage(App => props => ( const originalRenderPage = ctx.renderPage
<JssProvider registry={registry}> ctx.renderPage = () =>
<App {...props} /> originalRenderPage({
</JssProvider> enhanceApp: App => props => (
)) <JssProvider registry={registry}>
<App {...props} />
</JssProvider>
)
})
const initialProps = await Document.getInitialProps(ctx)
return { return {
...page, ...initialProps,
registry registry
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册