Skip to content
This repository was archived by the owner on Jun 25, 2020. It is now read-only.

Commit deec1d6

Browse files
committed
fix: render 0
1 parent 23f9ea5 commit deec1d6

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
import React, { useMemo } from 'react';
22
import dompurify from 'dompurify';
33

4+
const isHTML = RegExp.prototype.test.bind(/(<([^>]+)>)/i);
5+
46
export default function HTMLRenderer({ value }: { value: string }) {
5-
const html = useMemo(() => ({ __html: dompurify.sanitize(value) }), [value]);
7+
if (isHTML(value)) {
8+
const html = useMemo(() => ({ __html: dompurify.sanitize(value) }), [value]);
9+
10+
return (
11+
// eslint-disable-next-line react/no-danger
12+
<div dangerouslySetInnerHTML={html} />
13+
);
14+
}
615

7-
return (
8-
// eslint-disable-next-line react/no-danger
9-
<div dangerouslySetInnerHTML={html} />
10-
);
16+
return value;
1117
}

0 commit comments

Comments
 (0)