Skip to content

Commit

Permalink
move transformers inside the function component to avoid circular dep…
Browse files Browse the repository at this point in the history
… problems
  • Loading branch information
pettinarip committed Sep 6, 2024
1 parent 76bddad commit 3a48c35
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/components/Translation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,6 @@ type TranslationProps = {
transform?: HtmrOptions["transform"]
}

// Custom components mapping to be used by `htmr` when parsing the translation
// text
const defaultTransform = {
a: TooltipLink,
}

// Renders the translation string for the given translation key `id`. It
// fallback to English if it doesn't find the given key in the current language
const Translation = ({ id, options, transform = {} }: TranslationProps) => {
Expand All @@ -28,6 +22,12 @@ const Translation = ({ id, options, transform = {} }: TranslationProps) => {
const { t } = useTranslation(requiredNamespaces)
const translatedText = t(id, options)

// Custom components mapping to be used by `htmr` when parsing the translation
// text
const defaultTransform = {
a: TooltipLink,
}

// Use `htmr` to parse html content in the translation text
return htmr(translatedText, {
transform: { ...defaultTransform, ...transform },
Expand Down

0 comments on commit 3a48c35

Please sign in to comment.