Hydrate body ranges for story replies

This commit is contained in:
Fedor Indutny 2022-11-09 20:59:36 -08:00 committed by GitHub
parent 9f85db3fd8
commit be6e988a95
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
39 changed files with 221 additions and 172 deletions

View file

@ -27,13 +27,11 @@ export type Props = {
renderText?: RenderTextCallbackType;
};
export class Intl extends React.Component<Props> {
public static defaultProps: Partial<Props> = {
renderText: ({ text, key }) => (
<React.Fragment key={key}>{text}</React.Fragment>
),
};
const defaultRenderText: RenderTextCallbackType = ({ text, key }) => (
<React.Fragment key={key}>{text}</React.Fragment>
);
export class Intl extends React.Component<Props> {
public getComponent(
index: number,
placeholderName: string,
@ -74,7 +72,7 @@ export class Intl extends React.Component<Props> {
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
public override render() {
const { components, id, i18n, renderText } = this.props;
const { components, id, i18n, renderText = defaultRenderText } = this.props;
if (!id) {
log.error('Error: Intl id prop not provided');
@ -96,12 +94,6 @@ export class Intl extends React.Component<Props> {
> = [];
const FIND_REPLACEMENTS = /\$([^$]+)\$/g;
// We have to do this, because renderText is not required in our Props object,
// but it is always provided via defaultProps.
if (!renderText) {
return null;
}
if (Array.isArray(components) && components.length > 1) {
throw new Error(
'Array syntax is not supported with more than one placeholder'