Commit e1babdfe authored by Tim Neutkens's avatar Tim Neutkens Committed by Arunoda Susiripala

Render styled-jsx in _document example (#1287)

parent 1971517c
...@@ -4,7 +4,7 @@ import cxs from 'cxs' ...@@ -4,7 +4,7 @@ import cxs from 'cxs'
export default class MyDocument extends Document { export default class MyDocument extends Document {
static async getInitialProps ({ renderPage }) { static async getInitialProps ({ renderPage }) {
const page = renderPage() const page = renderPage()
let style = cxs.getCss() const style = cxs.getCss()
return { ...page, style } return { ...page, style }
} }
......
...@@ -4,8 +4,8 @@ import styleSheet from 'styled-components/lib/models/StyleSheet' ...@@ -4,8 +4,8 @@ import styleSheet from 'styled-components/lib/models/StyleSheet'
export default class MyDocument extends Document { export default class MyDocument extends Document {
static async getInitialProps ({ renderPage }) { static async getInitialProps ({ renderPage }) {
const page = renderPage() const page = renderPage()
const style = styleSheet.rules().map(rule => rule.cssText).join('\n') const styles = styleSheet.rules().map(rule => rule.cssText).join('\n')
return { ...page, style } return { ...page, styles }
} }
render () { render () {
...@@ -13,7 +13,6 @@ export default class MyDocument extends Document { ...@@ -13,7 +13,6 @@ export default class MyDocument extends Document {
<html> <html>
<Head> <Head>
<title>My page</title> <title>My page</title>
<style dangerouslySetInnerHTML={{ __html: this.props.style }} />
</Head> </Head>
<body> <body>
<Main /> <Main />
......
...@@ -473,11 +473,13 @@ Pages in `Next.js` skip the definition of the surrounding document's markup. For ...@@ -473,11 +473,13 @@ Pages in `Next.js` skip the definition of the surrounding document's markup. For
```jsx ```jsx
// ./pages/_document.js // ./pages/_document.js
import Document, { Head, Main, NextScript } from 'next/document' import Document, { Head, Main, NextScript } from 'next/document'
import flush from 'styled-jsx/server'
export default class MyDocument extends Document { export default class MyDocument extends Document {
static async getInitialProps (ctx) { static getInitialProps ({ renderPage }) {
const props = await Document.getInitialProps(ctx) const {html, head} = renderPage()
return { ...props, customValue: 'hi there!' } const styles = flush()
return { html, head, styles }
} }
render () { render () {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment