From c8a19c1664ac8e80acf3e254bba615b13ef480dd Mon Sep 17 00:00:00 2001 From: Ryan Miller Date: Thu, 28 Mar 2024 09:30:01 +1100 Subject: [PATCH] fix: add React.ElementType type to SessionHTMLRenderer and rename tag prop to as --- ts/components/basic/I18n.tsx | 2 +- ts/components/basic/SessionHTMLRenderer.tsx | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/ts/components/basic/I18n.tsx b/ts/components/basic/I18n.tsx index 5b29dcb71..c248a41ff 100644 --- a/ts/components/basic/I18n.tsx +++ b/ts/components/basic/I18n.tsx @@ -42,7 +42,7 @@ export const I18n = (props: I18nProps) => { /** If the string contains a relevant formatting tag, render it as HTML */ if (i18nString.match(formattingTagRegex)) { - return ; + return ; } const Comp = props.as ?? React.Fragment; diff --git a/ts/components/basic/SessionHTMLRenderer.tsx b/ts/components/basic/SessionHTMLRenderer.tsx index 7e5280a0b..83c0c46ea 100644 --- a/ts/components/basic/SessionHTMLRenderer.tsx +++ b/ts/components/basic/SessionHTMLRenderer.tsx @@ -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,