Skip to content

Commit

Permalink
Merge pull request #47 from opensquare-network/fix/watch-content-changes
Browse files Browse the repository at this point in the history
fix: watch content changes
  • Loading branch information
YoshiyukiSakura authored Aug 12, 2022
2 parents 91bbd54 + c14a5dd commit f8e5315
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
7 changes: 5 additions & 2 deletions demo/App.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -84,12 +84,15 @@ function MentionIdentityUser({ address = "", network = "" }) {
}

function App() {
const [md, setMd] = useState(mdFeatures);

return (
<div className="App">
<button onClick={() => setMd("## change md features")}>button</button>
<div className="features">
<div>
<h2>Features</h2>
<MarkdownPreviewer content={mdFeatures} />
<MarkdownPreviewer content={md} />
</div>

<div>
Expand Down
1 change: 1 addition & 0 deletions src/HtmlPreviewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export function HtmlPreviewer(props: PreviewerProps) {

const ref = useRef<HTMLDivElement>(null);
const [html, setHtml] = useState(content);
useEffect(() => setHtml(content), [content]);

useEffect(() => {
applyPlugins(resolvedPlugins, "transformHtml", html, setHtml);
Expand Down
4 changes: 3 additions & 1 deletion src/MarkdownPreviewer.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { marked, Renderer } from "marked";
import { useEffect, useState } from "react";

import { HtmlPreviewer } from "./HtmlPreviewer";
import { highLightPlugin } from "./plugins";
Expand All @@ -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 (
<HtmlPreviewer
Expand Down

0 comments on commit f8e5315

Please sign in to comment.