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

Render styled-jsx in _document example (#1287)

This commit is contained in:
Tim Neutkens 2017-02-28 00:45:49 +01:00 committed by Arunoda Susiripala
parent 1971517c17
commit e1babdfe9d
3 changed files with 8 additions and 7 deletions

View file

@ -4,7 +4,7 @@ import cxs from 'cxs'
export default class MyDocument extends Document {
static async getInitialProps ({ renderPage }) {
const page = renderPage()
let style = cxs.getCss()
const style = cxs.getCss()
return { ...page, style }
}

View file

@ -4,8 +4,8 @@ import styleSheet from 'styled-components/lib/models/StyleSheet'
export default class MyDocument extends Document {
static async getInitialProps ({ renderPage }) {
const page = renderPage()
const style = styleSheet.rules().map(rule => rule.cssText).join('\n')
return { ...page, style }
const styles = styleSheet.rules().map(rule => rule.cssText).join('\n')
return { ...page, styles }
}
render () {
@ -13,7 +13,6 @@ export default class MyDocument extends Document {
<html>
<Head>
<title>My page</title>
<style dangerouslySetInnerHTML={{ __html: this.props.style }} />
</Head>
<body>
<Main />

View file

@ -473,11 +473,13 @@ Pages in `Next.js` skip the definition of the surrounding document's markup. For
```jsx
// ./pages/_document.js
import Document, { Head, Main, NextScript } from 'next/document'
import flush from 'styled-jsx/server'
export default class MyDocument extends Document {
static async getInitialProps (ctx) {
const props = await Document.getInitialProps(ctx)
return { ...props, customValue: 'hi there!' }
static getInitialProps ({ renderPage }) {
const {html, head} = renderPage()
const styles = flush()
return { html, head, styles }
}
render () {