MCPcopy
hub / github.com/remarkjs/react-markdown / MarkdownHooks

Function MarkdownHooks

lib/index.js:214–252  ·  view source on GitHub ↗
(options)

Source from the content-addressed store, hash-verified

212 * React node.
213 */
214export function MarkdownHooks(options) {
215 const processor = createProcessor(options)
216 const [error, setError] = useState(
217 /** @type {Error | undefined} */ (undefined)
218 )
219 const [tree, setTree] = useState(/** @type {Root | undefined} */ (undefined))
220
221 useEffect(
222 function () {
223 let cancelled = false
224 const file = createFile(options)
225
226 processor.run(processor.parse(file), file, function (error, tree) {
227 if (!cancelled) {
228 setError(error)
229 setTree(tree)
230 }
231 })
232
233 /**
234 * @returns {undefined}
235 * Nothing.
236 */
237 return function () {
238 cancelled = true
239 }
240 },
241 [
242 options.children,
243 options.rehypePlugins,
244 options.remarkPlugins,
245 options.remarkRehypeOptions
246 ]
247 )
248
249 if (error) throw error
250
251 return tree ? post(tree, options) : options.fallback
252}
253
254/**
255 * Set up the `unified` processor.

Callers

nothing calls this directly

Calls 3

createProcessorFunction · 0.85
createFileFunction · 0.85
postFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…