Refactored TranslatedTag component from class-based to functional

This commit is contained in:
Przemek Wiech
2021-11-03 14:54:39 +01:00
parent fe5f68e77d
commit 15b79eaf39

View File

@@ -1,9 +1,4 @@
import {FormattedMessage, injectIntl, WrappedComponentProps} from 'react-intl'; import {FormattedMessage} from 'react-intl';
import * as React from 'react';
interface Props {
tag: string;
}
const TAG_DESCRIPTIONS = new Map([ const TAG_DESCRIPTIONS = new Map([
['ADOP', 'Adoption'], ['ADOP', 'Adoption'],
@@ -29,8 +24,12 @@ const TAG_DESCRIPTIONS = new Map([
['WWW', 'WWW'], ['WWW', 'WWW'],
]); ]);
function translateTag(tag: string) { interface Props {
const normalizedTag = tag.replace(/_/g, ''); tag: string;
}
export function TranslatedTag(props: Props) {
const normalizedTag = props.tag.replace(/_/g, '');
return ( return (
<FormattedMessage <FormattedMessage
id={`gedcom.${normalizedTag}`} id={`gedcom.${normalizedTag}`}
@@ -38,14 +37,3 @@ function translateTag(tag: string) {
/> />
); );
} }
class TranslatedTagComponent extends React.Component<
Props & WrappedComponentProps,
{}
> {
render() {
return translateTag(this.props.tag);
}
}
export const TranslatedTag = injectIntl(TranslatedTagComponent);