diff --git a/lib/index.js b/lib/index.js index 6e3fdd2..06f07e1 100644 --- a/lib/index.js +++ b/lib/index.js @@ -107,7 +107,7 @@ import {unreachable} from 'devlop' import {toJsxRuntime} from 'hast-util-to-jsx-runtime' import {urlAttributes} from 'html-url-attributes' import {Fragment, jsx, jsxs} from 'react/jsx-runtime' -import {useEffect, useState} from 'react' +import {useEffect, useMemo, useState} from 'react' import remarkParse from 'remark-parse' import remarkRehype from 'remark-rehype' import {unified} from 'unified' @@ -212,7 +212,12 @@ export async function MarkdownAsync(options) { * React node. */ export function MarkdownHooks(options) { - const processor = createProcessor(options) + const processor = useMemo( + function () { + return createProcessor(options) + }, + [options.rehypePlugins, options.remarkPlugins, options.remarkRehypeOptions] + ) const [error, setError] = useState( /** @type {Error | undefined} */ (undefined) ) @@ -238,12 +243,7 @@ export function MarkdownHooks(options) { cancelled = true } }, - [ - options.children, - options.rehypePlugins, - options.remarkPlugins, - options.remarkRehypeOptions - ] + [options.children, processor] ) if (error) throw error