2021-12-29 17:21:02 +00:00
|
|
|
import ReactDOMServer from 'react-dom/server'
|
|
|
|
import { SSRProvider } from '@react-aria/ssr'
|
|
|
|
import { StaticRouter } from 'react-router-dom'
|
|
|
|
import i18next from './locales/i18n'
|
2022-04-03 15:40:00 +00:00
|
|
|
import { AppFr } from './entry-fr'
|
|
|
|
import { AppEn } from './entry-en'
|
2021-12-29 17:21:02 +00:00
|
|
|
import { ServerStyleSheet, StyleSheetManager } from 'styled-components'
|
|
|
|
import { FilledContext, HelmetProvider } from 'react-helmet-async'
|
|
|
|
|
|
|
|
export function render(url: string, lang: 'fr' | 'en') {
|
|
|
|
const sheet = new ServerStyleSheet()
|
|
|
|
const helmetContext = {} as FilledContext
|
|
|
|
const App = lang === 'fr' ? AppFr : AppEn
|
2022-03-28 13:34:12 +00:00
|
|
|
i18next.changeLanguage(lang).catch((err) =>
|
|
|
|
// eslint-disable-next-line no-console
|
|
|
|
console.error(err)
|
|
|
|
)
|
2021-12-29 17:21:02 +00:00
|
|
|
|
|
|
|
const html = ReactDOMServer.renderToString(
|
2022-01-31 07:28:31 +00:00
|
|
|
<HelmetProvider context={helmetContext}>
|
|
|
|
<SSRProvider>
|
2021-12-29 17:21:02 +00:00
|
|
|
<StyleSheetManager sheet={sheet.instance}>
|
|
|
|
<StaticRouter location={url}>
|
|
|
|
<App />
|
|
|
|
</StaticRouter>
|
|
|
|
</StyleSheetManager>
|
2022-01-31 07:28:31 +00:00
|
|
|
</SSRProvider>
|
|
|
|
</HelmetProvider>
|
2021-12-29 17:21:02 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const styleTags = sheet.getStyleTags()
|
|
|
|
|
|
|
|
return { html, styleTags, helmet: helmetContext.helmet }
|
|
|
|
}
|