Skip to content

Commit

Permalink
fix(react): clear before render
Browse files Browse the repository at this point in the history
  • Loading branch information
pd4d10 committed Jun 13, 2020
1 parent ae46593 commit afe4cab
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions packages/bytemd/react/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ export interface EditorProps extends bytemd.EditorProps {
}

export const Editor: React.FC<EditorProps> = (props) => {
const ins = useRef<bytemd.Editor>();
const ed = useRef<bytemd.Editor>();
const el = useRef<HTMLDivElement>(null);

useEffect(() => {
if (!el.current) return;
if (ed.current) ed.current.$destroy();

const editor = new bytemd.Editor({
target: el.current,
Expand All @@ -21,7 +22,7 @@ export const Editor: React.FC<EditorProps> = (props) => {
props.onChange(e.detail.value);
}
});
ins.current = editor;
ed.current = editor;
}, [el.current]);

return <div ref={el}></div>;
Expand Down

0 comments on commit afe4cab

Please sign in to comment.