Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

_app.tsx 2.0 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
  1. import React, { useEffect } from 'react'
  2. import App from 'next/app'
  3. import type { AppProps, AppContext } from 'next/app'
  4. import Head from 'next/head'
  5. import { useTheme, ThemeProvider } from '@primer/components'
  6. import { getThemeProps } from 'components/lib/getThemeProps'
  7. import '../stylesheets/index.scss'
  8. import { defaultThemeProps } from 'components/lib/getThemeProps'
  9. type MyAppProps = AppProps & { csrfToken: string; themeProps: typeof defaultThemeProps }
  10. const MyApp = ({ Component, pageProps, csrfToken, themeProps }: MyAppProps) => {
  11. return (
  12. <>
  13. <Head>
  14. <meta charSet="utf-8" />
  15. <title>GitHub Documentation</title>
  16. <meta name="viewport" content="width=device-width, initial-scale=1" />
  17. <link rel="alternate icon" type="image/png" href="/assets/images/site/favicon.png" />
  18. <link rel="icon" type="image/svg+xml" href="/assets/images/site/favicon.svg" />
  19. <meta
  20. name="google-site-verification"
  21. content="OgdQc0GZfjDI52wDv1bkMT-SLpBUo_h5nn9mI9L22xQ"
  22. />
  23. <meta
  24. name="google-site-verification"
  25. content="c1kuD-K2HIVF635lypcsWPoD4kilo5-jA_wBFyT4uMY"
  26. />
  27. <meta name="csrf-token" content={csrfToken} />
  28. </Head>
  29. <ThemeProvider>
  30. <SetTheme themeProps={themeProps} />
  31. <Component {...pageProps} />
  32. </ThemeProvider>
  33. </>
  34. )
  35. }
  36. MyApp.getInitialProps = async (appContext: AppContext) => {
  37. const { ctx } = appContext
  38. // calls page's `getInitialProps` and fills `appProps.pageProps`
  39. const appProps = await App.getInitialProps(appContext)
  40. const req: any = ctx.req
  41. return { ...appProps, themeProps: getThemeProps(req), csrfToken: req?.csrfToken?.() || '' }
  42. }
  43. const SetTheme = ({ themeProps }: { themeProps: typeof defaultThemeProps }) => {
  44. // Cause primer/components to re-evaluate the 'auto' color mode on client side render
  45. const { setColorMode } = useTheme()
  46. useEffect(() => {
  47. setTimeout(() => {
  48. setColorMode(themeProps.colorMode as any)
  49. })
  50. }, [])
  51. return null
  52. }
  53. export default MyApp
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...