Skip to content

Commit

Permalink
feat: allow passing translations to ComponentWrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
dmeijboom committed Nov 19, 2024
1 parent a5fcd44 commit b955e6f
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/markup-components/component-wrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,21 @@

import { FunctionComponent } from "react"
import ReactDOMServer from "react-dom/server"
import { IntlProvider } from "../react-components"
import * as locales from "../locales"
import {
CustomTranslations,
IntlProvider,
SupportedTranslations,
} from "../react-components"

export type Context = {
locale?: keyof typeof locales
}
export type Context = SupportedTranslations | CustomTranslations

export const ComponentWrapper = <Props extends {}>(
Component: FunctionComponent<Props>,
props: Props,
{ locale = "en" }: Context,
ctx: Context,
) => {
return ReactDOMServer.renderToStaticMarkup(
<IntlProvider locale={locale}>
<IntlProvider<typeof ctx> {...ctx}>
<Component {...props} />
</IntlProvider>,
)
Expand Down

0 comments on commit b955e6f

Please sign in to comment.