1
1
/**
2
2
* @import {Element, Nodes, Parents, Root} from 'hast'
3
3
* @import {Root as MdastRoot} from 'mdast'
4
- * @import {ComponentType, JSX, ReactElement} from 'react'
4
+ * @import {ComponentType, JSX, ReactElement, ReactNode } from 'react'
5
5
* @import {Options as RemarkRehypeOptions} from 'remark-rehype'
6
6
* @import {BuildVisitor} from 'unist-util-visit'
7
7
* @import {PluggableList, Processor} from 'unified'
77
77
* Change URLs (default: `defaultUrlTransform`)
78
78
*/
79
79
80
+ /**
81
+ * @typedef HooksOptionsOnly
82
+ * Configuration specifically for {@link MarkdownHooks}
83
+ * @property {ReactNode } [fallback]
84
+ * A fallback node to render while the processor isn’t done processing the markdown.
85
+ */
86
+
87
+ /**
88
+ * @typedef {Options & HooksOptionsOnly } HooksOptions
89
+ * Configuration for {@link MarkdownHooks}
90
+ */
91
+
80
92
/**
81
93
* @callback UrlTransform
82
94
* Transform all URLs.
@@ -94,7 +106,7 @@ import {unreachable} from 'devlop'
94
106
import { toJsxRuntime } from 'hast-util-to-jsx-runtime'
95
107
import { urlAttributes } from 'html-url-attributes'
96
108
import { Fragment , jsx , jsxs } from 'react/jsx-runtime'
97
- import { createElement , useEffect , useState } from 'react'
109
+ import { useEffect , useState } from 'react'
98
110
import remarkParse from 'remark-parse'
99
111
import remarkRehype from 'remark-rehype'
100
112
import { unified } from 'unified'
@@ -193,10 +205,10 @@ export async function MarkdownAsync(options) {
193
205
* For async support on the server,
194
206
* see {@linkcode MarkdownAsync}.
195
207
*
196
- * @param {Readonly<Options > } options
208
+ * @param {Readonly<HooksOptions > } options
197
209
* Props.
198
- * @returns {ReactElement }
199
- * React element .
210
+ * @returns {ReactNode }
211
+ * React node .
200
212
*/
201
213
export function MarkdownHooks ( options ) {
202
214
const processor = createProcessor ( options )
@@ -223,7 +235,7 @@ export function MarkdownHooks(options) {
223
235
224
236
if ( error ) throw error
225
237
226
- return tree ? post ( tree , options ) : createElement ( Fragment )
238
+ return tree ? post ( tree , options ) : options . fallback
227
239
}
228
240
229
241
/**
0 commit comments