fix: add React.ElementType type to SessionHTMLRenderer and rename tag prop to as

pull/3206/head
Ryan Miller 1 year ago
parent 0382d4f0dc
commit c8a19c1664

@ -42,7 +42,7 @@ export const I18n = <T extends LocalizerToken>(props: I18nProps<T>) => {
/** If the string contains a relevant formatting tag, render it as HTML */
if (i18nString.match(formattingTagRegex)) {
return <SessionHtmlRenderer tag={props.as} html={i18nString} />;
return <SessionHtmlRenderer as={props.as} html={i18nString} />;
}
const Comp = props.as ?? React.Fragment;

@ -1,20 +1,20 @@
import React from 'react';
import DOMPurify from 'dompurify';
import React from 'react';
type ReceivedProps = {
html: string;
tag?: string;
as?: React.ElementType;
key?: any;
className?: string;
};
export const SessionHtmlRenderer = ({ tag = 'div', key, html, className }: ReceivedProps) => {
export const SessionHtmlRenderer = ({ as = 'div', key, html, className }: ReceivedProps) => {
const clean = DOMPurify.sanitize(html, {
USE_PROFILES: { html: true },
FORBID_ATTR: ['script'],
});
return React.createElement(tag, {
return React.createElement(as, {
key,
className,

Loading…
Cancel
Save