diff --git a/demo/App.tsx b/demo/App.tsx index 8d016fa..bce9c25 100644 --- a/demo/App.tsx +++ b/demo/App.tsx @@ -1,4 +1,4 @@ -import React from "react"; +import React, { useState } from "react"; import { HtmlPreviewer } from "../src/HtmlPreviewer"; import { MarkdownPreviewer } from "../src/MarkdownPreviewer"; import { renderMentionIdentityUserPlugin } from "../src/plugins"; @@ -84,12 +84,15 @@ function MentionIdentityUser({ address = "", network = "" }) { } function App() { + const [md, setMd] = useState(mdFeatures); + return (
+

Features

- +
diff --git a/src/HtmlPreviewer.tsx b/src/HtmlPreviewer.tsx index 45ac4d9..39f726d 100644 --- a/src/HtmlPreviewer.tsx +++ b/src/HtmlPreviewer.tsx @@ -27,6 +27,7 @@ export function HtmlPreviewer(props: PreviewerProps) { const ref = useRef(null); const [html, setHtml] = useState(content); + useEffect(() => setHtml(content), [content]); useEffect(() => { applyPlugins(resolvedPlugins, "transformHtml", html, setHtml); diff --git a/src/MarkdownPreviewer.tsx b/src/MarkdownPreviewer.tsx index 2411c55..315896f 100644 --- a/src/MarkdownPreviewer.tsx +++ b/src/MarkdownPreviewer.tsx @@ -1,4 +1,5 @@ import { marked, Renderer } from "marked"; +import { useEffect, useState } from "react"; import { HtmlPreviewer } from "./HtmlPreviewer"; import { highLightPlugin } from "./plugins"; @@ -24,7 +25,8 @@ export function MarkdownPreviewer(props: PreviewerProps) { applyPlugins(resolvePlugins, "markedOptions", markedOptions); - const html = marked.parse(content, markedOptions); + const [html, setHtml] = useState(""); + useEffect(() => setHtml(marked.parse(content, markedOptions)), [content]); return (