5d2e960c6c
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.
34 lines
822 B
JavaScript
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
|