MCPcopy Create free account
hub / github.com/dabbott/react-native-express / MyDocument

Class MyDocument

pages/_document.tsx:7–33  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5/* TODO: Render <html> with lang */
6
7export default class MyDocument extends Document {
8 static async getInitialProps(ctx: DocumentContext) {
9 const sheet = new ServerStyleSheet()
10 const originalRenderPage = ctx.renderPage
11
12 try {
13 ctx.renderPage = () =>
14 originalRenderPage({
15 enhanceApp: (App) => (props) =>
16 sheet.collectStyles(<App {...props} />),
17 })
18
19 const initialProps = await Document.getInitialProps(ctx)
20 return {
21 ...initialProps,
22 styles: (
23 <>
24 {initialProps.styles}
25 {sheet.getStyleElement()}
26 </>
27 ),
28 }
29 } finally {
30 sheet.seal()
31 }
32 }
33}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected