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 * as React from 'react';
interface Props {
tag: string;
}
import {FormattedMessage} from 'react-intl';
const TAG_DESCRIPTIONS = new Map([
['ADOP', 'Adoption'],
@@ -29,8 +24,12 @@ const TAG_DESCRIPTIONS = new Map([
['WWW', 'WWW'],
]);
function translateTag(tag: string) {
const normalizedTag = tag.replace(/_/g, '');
interface Props {
tag: string;
}
export function TranslatedTag(props: Props) {
const normalizedTag = props.tag.replace(/_/g, '');
return (
<FormattedMessage
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);