-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgatsby-shared.tsx
48 lines (41 loc) · 1.35 KB
/
gatsby-shared.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
39
40
41
42
43
44
45
46
47
48
import { isValidElement } from 'react'
import type { FunctionComponent, JSX, PropsWithChildren } from 'react'
import type { GatsbyBrowser, GatsbySSR } from 'gatsby'
import type { RouterContextProps } from '@gatsbyjs/reach-router'
import { BaseContext } from '@gatsbyjs/reach-router'
import { IntlProvider } from 'react-intl'
import messages from 'translations/ja.yml'
import Layout from 'components/Layout'
import Container from 'components/Container'
import { SearchProvider } from 'components/Search'
const Wrapper: FunctionComponent<PropsWithChildren> = ({ children }) => isValidElement(children) ? children : null
const base: RouterContextProps = {
basepath: '/',
component: Wrapper,
primary: false,
}
export const wrapPageElement: GatsbyBrowser<unknown, Context>['wrapPageElement'] & GatsbySSR<unknown, Context>['wrapPageElement'] = ({
element,
props: {
pageContext: {
sidebar,
},
},
}): JSX.Element => (
<Layout>
<Container sidebar={sidebar !== false}>
{element}
</Container>
</Layout>
)
export const wrapRootElement: GatsbyBrowser['wrapRootElement'] & GatsbySSR['wrapRootElement'] = ({
element,
}): JSX.Element => (
<IntlProvider locale="ja" messages={messages}>
<SearchProvider>
<BaseContext.Provider value={base}>
{element}
</BaseContext.Provider>
</SearchProvider>
</IntlProvider>
)