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

Function GuidebookApp

pages/_app.tsx:44–164  ·  view source on GitHub ↗
({
  Component,
  pageProps,
  router,
  locale,
  guidebook,
}: AppProps & {
  locale: string
  guidebook: TreeNode
})

Source from the content-addressed store, hash-verified

42const { locales, defaultLocale } = config.i18n!
43
44export default function GuidebookApp({
45 Component,
46 pageProps,
47 router,
48 locale,
49 guidebook,
50}: AppProps & {
51 locale: string
52 guidebook: TreeNode
53}) {
54 const localePrefix = locale === defaultLocale ? '' : `/${locale}`
55
56 const LinkComponent = useMemo(() => {
57 return ({ href, children, style }: LinkProps) => (
58 <Link
59 href={isExternalUrl(href) ? href : `${localePrefix}${href}`}
60 passHref
61 >
62 <Anchor style={style}>{children}</Anchor>
63 </Link>
64 )
65 }, [localePrefix])
66
67 const Components = useMemo(
68 () => ({
69 ...PageComponents,
70 Example: EditorConsole,
71 Author,
72 FileTreeDiagram,
73 Details: ({ children }: { children: React.ReactNode }) => children,
74 a: LinkComponent,
75 }),
76 [LinkComponent]
77 )
78
79 // Use `asPath`, since `pathname` will be "_error" if the page isn't found
80 const pathname = router.pathname.slice(localePrefix.length)
81 const clientPath = router.asPath.slice(localePrefix.length)
82 const theme = pathname.endsWith('slides') ? slidesTheme : defaultTheme
83
84 let content
85 let title: string
86 let description: string | undefined
87
88 const node = findNodeBySlug(guidebook, pathname.slice(1))
89
90 if (node) {
91 const isIntroduction = node.slug === ''
92
93 title = node.title
94 description = node.subtitle
95 content = (
96 <MDXProvider components={Components}>
97 <Page
98 rootNode={guidebook}
99 header={
100 isIntroduction ? (
101 <Banner logo={logo} github={config.github} />

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected