rsnext/examples/with-stitches/pages/_document.js

33 lines
755 B
JavaScript
Raw Normal View History

2020-05-02 06:30:39 +02:00
import Document from 'next/document'
import { css } from '../css'
2020-05-02 06:30:39 +02:00
export default class MyDocument extends Document {
static async getInitialProps(ctx) {
const originalRenderPage = ctx.renderPage
try {
let extractedStyles
ctx.renderPage = () => {
const { styles, result } = css.getStyles(originalRenderPage)
extractedStyles = styles
return result
}
2020-05-02 06:30:39 +02:00
const initialProps = await Document.getInitialProps(ctx)
2020-05-02 06:30:39 +02:00
return {
...initialProps,
styles: (
<>
{initialProps.styles}
{extractedStyles.map((content, index) => (
<style key={index}>{content}</style>
2020-05-02 06:30:39 +02:00
))}
</>
),
}
} finally {
}
}
}