Projekt

Obecné

Profil

Stáhnout (462 Bajtů) Statistiky
| Větev: | Tag: | Revize:
1
import DOMPurify from 'dompurify'
2
import { ReactNode } from 'react'
3

    
4
/**
5
 * Formats HTML string to safe virtual DOM nodes.
6
 * @param htmlString string to format
7
 */
8
export const formatHtmlStringToReactDom = (htmlString: string, defaultValue: string = '-'): ReactNode => {
9
    if (!htmlString || htmlString.length === 0) {
10
        return defaultValue
11
    }
12
    return (
13
        <div dangerouslySetInnerHTML={{ __html: DOMPurify.sanitize(htmlString) }} />
14
    )
15
}
    (1-1/1)