MCPcopy Create free account
hub / github.com/github/docs / getInitialProps

Method getInitialProps

pages/_document.tsx:7–30  ·  view source on GitHub ↗
(ctx: DocumentContext)

Source from the content-addressed store, hash-verified

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

Callers 1

_app.tsxFile · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected