session-desktop/ts/components/session/SessionHTMLRenderer.tsx
2021-04-22 18:03:58 +10:00

26 lines
602 B
TypeScript

import React from 'react';
import DOMPurify from 'dompurify';
interface ReceivedProps {
html: string;
tag?: string;
key?: any;
className?: string;
}
// Needed because of https://github.com/microsoft/tslint-microsoft-contrib/issues/339
type Props = ReceivedProps;
export const SessionHtmlRenderer: React.SFC<Props> = ({ tag = 'div', key, html, className }) => {
const clean = DOMPurify.sanitize(html, {
USE_PROFILES: { html: true },
FORBID_ATTR: ['script'],
});
return React.createElement(tag, {
key,
className,
dangerouslySetInnerHTML: { __html: clean },
});
};