Skip to content

Commit 6630d01

Browse files
committed
refactor: improved dom-to-react, type
Release-As: 5.1.2
1 parent ebaaf8d commit 6630d01

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

src/dom-to-react.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ const React = {
2828
*/
2929
export default function domToReact(
3030
nodes: DOMNode[],
31-
options?: HTMLReactParserOptions,
31+
options: HTMLReactParserOptions = {},
3232
): string | JSX.Element | JSX.Element[] {
3333
const reactElements = [];
3434

35-
const hasReplace = typeof options?.replace === 'function';
36-
const transform = options?.transform || returnFirstArg;
35+
const hasReplace = typeof options.replace === 'function';
36+
const transform = options.transform || returnFirstArg;
3737
const { cloneElement, createElement, isValidElement } =
38-
options?.library || React;
38+
options.library || React;
3939

4040
const nodesLength = nodes.length;
4141

@@ -75,7 +75,7 @@ export default function domToReact(
7575

7676
// Trim is enabled and we have a whitespace node
7777
// so skip it
78-
if (options?.trim && isWhitespace) {
78+
if (options.trim && isWhitespace) {
7979
continue;
8080
}
8181

src/types.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,13 @@ export interface HTMLReactParserOptions {
1010
cloneElement: (
1111
element: JSX.Element,
1212
props?: object,
13-
...children: any
13+
...children: any[]
14+
) => JSX.Element;
15+
createElement: (
16+
type: any,
17+
props?: object,
18+
...children: any[]
1419
) => JSX.Element;
15-
createElement: (type: any, props?: object, ...children: any) => JSX.Element;
1620
isValidElement: (element: any) => boolean;
1721
[key: string]: any;
1822
};

0 commit comments

Comments
 (0)