rsnext/examples/with-filbert/pages/_document.js
anotherjsguy 5d2e960c6c
(chore) Add with-filbert as example (#15161)
This PR adds an example for [filbert-js](https://filbert-js.vercel.app/docs/introduction) 🖌️
I have locally run the example & it's working as expected.
2020-07-16 23:05:04 +00:00

34 lines
822 B
JavaScript

import Document from 'next/document'
import { createStylesheet } from '@filbert-js/server-stylesheet'
class MyDocument extends Document {
static async getInitialProps(ctx) {
const sheet = createStylesheet()
const originalRenderPage = ctx.renderPage
try {
ctx.renderPage = () =>
originalRenderPage({
enhanceApp: (App) => {
return (props) => {
return sheet.collectStyles(<App {...props} />)
}
},
})
const initialProps = await Document.getInitialProps(ctx)
const styleTags = sheet.getReactElements()
return {
...initialProps,
styles: (
<>
{styleTags}
{initialProps.styles}
</>
),
}
} finally {
}
}
}
export default MyDocument