From 4f8d5d1a9393e20dc3b21d5042c998bb97644ad0 Mon Sep 17 00:00:00 2001 From: Remco Haszing Date: Fri, 18 Apr 2025 19:51:16 +0200 Subject: [PATCH] Create processor in useEffect in MarkdownHooks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In `MarkdownHooks` we don’t need to create the processor for every render. We only need it inside the effect. --- lib/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/index.js b/lib/index.js index 6e3fdd2..6e0150c 100644 --- a/lib/index.js +++ b/lib/index.js @@ -212,7 +212,6 @@ export async function MarkdownAsync(options) { * React node. */ export function MarkdownHooks(options) { - const processor = createProcessor(options) const [error, setError] = useState( /** @type {Error | undefined} */ (undefined) ) @@ -221,6 +220,7 @@ export function MarkdownHooks(options) { useEffect( function () { let cancelled = false + const processor = createProcessor(options) const file = createFile(options) processor.run(processor.parse(file), file, function (error, tree) {