mirror of
https://github.com/glitch-soc/mastodon.git
synced 2026-03-29 03:00:33 +02:00
Port 1820a03622 to glitch-soc
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Signed-off-by: Claire <claire.github-309c@sitedethib.com>
27 lines
792 B
TypeScript
27 lines
792 B
TypeScript
import type { ComponentClass } from 'react';
|
|
|
|
import { useIntl } from 'react-intl';
|
|
|
|
interface IntlHocProps<TProps extends Record<string, unknown>> {
|
|
component: ComponentClass<TProps>;
|
|
props: TProps;
|
|
}
|
|
|
|
export const IntlHoc = <TProps extends Record<string, unknown>>({
|
|
component: Component,
|
|
props,
|
|
}: IntlHocProps<TProps>) => {
|
|
const intl = useIntl();
|
|
return <Component {...props} intl={intl} />;
|
|
};
|
|
|
|
export const injectIntl = <TProps extends Record<string, unknown>>(
|
|
Component: ComponentClass<TProps>,
|
|
) => {
|
|
const WrappedComponent = (props: Omit<TProps, 'intl'>) => (
|
|
<IntlHoc component={Component} props={props as TProps} />
|
|
);
|
|
WrappedComponent.displayName = `injectIntl(${(Component.displayName ?? Component.name) || 'Component'})`;
|
|
return WrappedComponent;
|
|
};
|