forked from nodejs/nodejs.org
-
Notifications
You must be signed in to change notification settings - Fork 0
/
theme.tsx
38 lines (33 loc) · 1.49 KB
/
theme.tsx
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
import { memo } from 'react';
import type { FC, PropsWithChildren } from 'react';
import HtmlHead from './components/HtmlHead';
import { LayoutProvider } from './providers/layoutProvider';
import { MDXProvider } from './providers/mdxProvider';
import type { DynamicStaticProps } from './types';
type ThemeProps = PropsWithChildren<DynamicStaticProps>;
// This is the Dynamic Page Theme Component that supports Dynamic MDX Page Rendering
// With the dynamic MDXProvider Component.
// @TODO: When migrating to the new Layout approach, each Layout should manually invoke the MDXProvider
// @TODO: And use the MDX Content, Frontmatter, Headings and Children as seemed fit.
const Theme: FC<ThemeProps> = ({ content, frontmatter = {}, children }) => (
<>
<HtmlHead frontMatter={frontmatter} />
<LayoutProvider frontMatter={frontmatter}>
{content && <MDXProvider content={content} />}
{children}
</LayoutProvider>
</>
);
export default memo(
Theme,
// The Theme Component is supposed to be used only for static Children or MDXRemote content
// that comes from `getStaticProps`. This means that the `props` should never change.
// At least the `props.content` should never. We should not calculate based on `children`
// As this component should never have a dynamic children
(
{ content: pContent, frontmatter: pFrontmatter },
{ content: nContent, frontmatter: nFrontmatter }
) =>
JSON.stringify([pContent, pFrontmatter]) ===
JSON.stringify([nContent, nFrontmatter])
);