-
Notifications
You must be signed in to change notification settings - Fork 4.3k
/
raw-html.js
27 lines (25 loc) · 1017 Bytes
/
raw-html.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/**
* Internal dependencies
*/
import { createElement } from './react';
// Disable reason: JSDoc linter doesn't seem to parse the union (`&`) correctly.
/** @typedef {{children: string} & import('react').ComponentPropsWithoutRef<'div'>} RawHTMLProps */
/**
* Component used as equivalent of Fragment with unescaped HTML, in cases where
* it is desirable to render dangerous HTML without needing a wrapper element.
* To preserve additional props, a `div` wrapper _will_ be created if any props
* aside from `children` are passed.
*
* @param {RawHTMLProps} props Children should be a string of HTML. Other props
* will be passed through to div wrapper.
*
* @return {JSX.Element} Dangerously-rendering component.
*/
export default function RawHTML( { children, ...props } ) {
// The DIV wrapper will be stripped by serializer, unless there are
// non-children props present.
return createElement( 'div', {
dangerouslySetInnerHTML: { __html: children },
...props,
} );
}